lecture 11 image processing 2017 1 with notes · representations of an image • recall that we can...

36
Image analysis CS/CME/BioE/Biophys/BMI 279 Oct. 31 and Nov. 2, 2017 Ron Dror 1

Upload: others

Post on 18-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Imageanalysis

CS/CME/BioE/Biophys/BMI279Oct.31andNov.2,2017

RonDror

1

Page 2: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Outline

• Images in molecular and cellular biology • Reducing image noise

– Mean and Gaussian filters – Frequency domain interpretation – Median filter

• Sharpening images • Image description and classification • Practical image processing tips

2

Page 3: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Images in molecular and cellular biology

3

Page 4: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Most of what we know about the structure of cells come from imaging

• Light microscopy, including fluorescence microscopy

• Electron microscopy

4

https://www.microscopyu.com/articles/livecellimaging/livecellmaintenance.html

http://blog.library.gsu.edu/wp-content/uploads/2010/11/mtdna.jpg

Fluorescencemicroscopyiswhereyoulabelparticularproteinsorothertargetswithamoleculethatglows,soyoucandistinguishthatspecifictargetfromeverythingelseintheimage.

Infact,sometechniqueswe’lldiscusslateronrequireyoutodolotsofcomputationBEFOREyoucanevenseethepicture.

Page 5: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Imaging is pervasive in structural biology

• The experimental techniques used to determine macromolecular (e.g., protein) structure also depend on imaging

5

http://debkellylab.org/?page_id=94

Single-particlecryo-electronmicroscopyX-raycrystallography

https://askabiologist.asu.edu/sites/default/files/resources/articles/crystal_clear/CuZn_SOD_C2_x-ray_diffraction_250.jpg

Page 6: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Computation plays an essential role in these imaging-based techniques

• We will start with analysis of microscopy data, because it’s closest to our everyday experience with images

• In fact, the basic image analysis techniques we’ll cover initially also apply to normal photographs

6

Page 7: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Representations of an image• Recall that we can think of a grayscale

image as: – A function of two variables (x and y) – A two-dimensional array of brightness

values – A matrix (of brightness values)

• A color image can be treated as: – Three separate images, one for each color

channel (red, green, blue) – A function that returns three values (red,

green, blue) for each (x, y) pair

7

x

y

WhereasEinsteinproposedtheconceptofmass-energyequivalence,ProfessorMihailNazarov,66,proposedmonkey-Einsteinequivalence.Fromhttp://www.nydailynews.com/news/world/baby-monkey-albert-einstein-article-1.1192365

Bytheway,whydoweusethreecolorchannels?becauseweonlyhavethreekindsofconesinoureyesthatdetectcolor,sothreechannelsaresufficienttodescribethecolorsweperceive.

Page 8: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Reducing image noise

8

Page 9: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Experimentally determined images are always corrupted by noise

• “Noise” means any deviation from what the image would ideally look like

9http://www.siox.org/pics/pferd-noisy.jpg

Page 10: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Image noise

10

Originalimage

Noisyimages

“Gaussiannoise”:normallydistributednoiseaddedtoeachpixel

“Saltandpepernoise”:randompixelsreplacedbyverybrightordarkvalues

Therearemanydifferentkindsofnoise,whichdependsonhowyou’remakingthemeasurement.Twocommonkindsare“gaussiannoise”or“saltandpeppernoise”

Howwouldyoude-noiseimageslikethis?Foreachpixel,maybeaveragethevaluesofnearbypixels.

Page 11: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Reducing image noise

11

Mean and Gaussian filters

Page 12: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

How can we reduce the noise in an image?

• The simplest way is to use a “mean filter” – Replace each pixel by the average of a set of pixels

surrounding it – For example, a 3x3 mean filter replaces each pixel with the

average of a 3x3 square of pixels – This is equivalent to convolving the image with a 3x3 matrix:

12Values should sum to 1, so that overall brightness of the image remains constant

19

19

19

19

19

19

19

19

19

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

= 19

1 1 11 1 11 1 1

⎢⎢⎢

⎥⎥⎥

Why 1/9?

Oryoucoulduse5x5matrix,orlarger.4x4istrickierbecausethenyoucan’tcenteritaroundthetargetpixel.

Forcorner/edgepixels,justaveragetheexistingsurroundingpixelsandignoremissingones.

Page 13: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Resultof3x3meanfilter

Originalimages

Mean filter

13

Alargerfilter(e.g.,5x5,7x7)wouldfurtherreducenoise,butwouldblurtheimagemore

Afterthemeanfilter,noiseislowerbutimagesareblurrier.Blurringcomesfromaveragingattheboundariesbetweentwocolors.Asthefiltersizebecomesbigger,youreducethenoisemorebecauseyou’reaveragingovermorepixels,butyoualsoblurtheimagemore.Ifyouknowthatyourimagewillconsistofregionsofsolidcolors,youcandofancierthingsthatdetecttheedgelocations.Butyoucan’tdothisformanyimages,suchasforimagesofcells.

Page 14: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

A better choice: use a smoother filter

• We can achieve a better tradeoff between noise reduction and distortion of the noise-free image by convolving the image with a smoother function

• One common choice is a (two-dimensional) Gaussian

14Ratherthanchoosingexactfiltersize(3x3,5x5,etc.),choosetheGaussianstandarddeviationσ(e.g.σ=1pixel,2pixels,etc.)

Page 15: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

ResultofGaussianfilter(standarddeviationσ=1pixel)

Originalimages

Gaussian filter

15

UsingalargerGaussianwouldfurtherreducenoise,butwouldblurtheimagemore

Page 16: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Filteredimages

Originalimages

Mean filter (for comparison)

16

Page 17: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Gaussian filter (for comparison)

17

Filteredimages

Originalimages

Page 18: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Reducing image noise

18

Frequency domain interpretation

Page 19: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Low-pass filtering

• Because the mean and Gaussian filters are convolutions, we can express them as multiplications in the frequency domain

• Both types of filters reduce high frequencies while preserving low frequencies. They are thus known as low-pass filters

• These filters work because real images have mostly low-frequency content, while noise tends to have a lot of high-frequency content

19

Inotherwords,mostofthelowfrequencyinformationinthenoisyimagecomesfromtherealimage,whilemostofthehighfrequencyinformationinthenoisyimagecomesfromthenoise.Soifyoureducehighfrequenciesintheimage,youcanpreferentiallyreducethenoise.Thisislikere-weightingthefrequencycomponentssothatthelowfrequencysignalstaysstrongbutthehigherfrequencysignalisweakened.ThisisbestdoneinFourierspace.

Page 20: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Low-pass filtering

20

Filterinrealdomain

Magnitudeprofileinfrequencydomain(lowfrequenciesarenearcenterofplots)

Gaussianfilter Meanfilter

TheGaussianfiltereliminateshighfrequenciesmoreeffectivelythanthemeanfilter,makingtheGaussianfilterbetterbymostmeasures.

UseaFouriertransformtogofromthetopimages(realdomain)tothebottomimages(frequencydomain).Note:FouriertransformofaGaussianisanotherGaussian

Page 21: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Low-pass filtering

• As a filter becomes larger (wider), its Fourier-domain representation becomes narrower

• In other words, making a mean or Gaussian filter larger will make it more low-pass (i.e, narrow the range of frequencies it passes) – Thus it will eliminate noise better, but blur the original

image more

21

Page 22: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Reducing image noise

22

Median filter

Page 23: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Median filter

• A median filter ranks the pixels in a square surrounding the pixel of interest, and picks the middle value

• This is particularly effective at eliminating noise that corrupts only a few pixel values (e.g., salt-and-pepper noise)

• This filter is not a convolution

23

Page 24: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Resultof3x3medianfilter

Originalimages

Median filter

24

Usingalargerwindowwouldfurtherreducenoise,butwoulddistorttheimagemore

Page 25: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Sharpening images

25

Page 26: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

High-pass filter• A high-pass filter removes (or reduces) low-frequency

components of an image, but not high-frequency ones • The simplest way to create a high-pass filter is to subtract a low-

pass filtered image from the original image – This removes the low frequencies but preserves the high ones – The filter matrix itself can be computed by subtracting a low-pass filter

matrix (that sums to 1) from an “identity” filter matrix (all zeros except for a 1 in the central pixel)

26

Originalimage Low-passfilteredimage High-passfilteredimage

– =

Note:thegreycolornowcorrespondsto0.Black/whitevaluesshowupatchanges(edges)intheoriginalimage

Page 27: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

How might one use a high-pass filter?• To highlight edges in the image • To remove any “background” brightness that varies smoothly across

the image • Image sharpening

– To sharpen the image, one can add a high-pass filtered version of the image (multiplied by a fractional scaling factor) to the original image

– This increases the high-frequency content relative to low-frequency content – In photography, this is called “unsharp masking”

27

https://upload.wikimedia.org/wikipedia/commons/0/0b/Accutance_example.png

OriginalimageMildsharpening(smallscalefactor)

Strongersharpening(largerscalefactor)

Youdon’twanttoactuallyfilteroutlow-frequencystuff,becauseitcontainsthemostimportantinformation.

Page 28: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Image sharpening — another example

28

http://www.exelisvis.com/docs/html/images/unsharp_mask_ex1.gif

Originalimage Sharpenedimage

Page 29: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Image description and classification

29

Page 30: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Describing images concisely

• The space of all possible images is very large. To fully describe an N-by-N pixel grayscale image, we need to specify N2 pixel values.

• We can thus think of a single image as a point in an N2-dimensional space.

• Classifying and analyzing images becomes easier if we can describe them (even approximately) with fewer values.

• For many classes of images, we can capture most of the variation from image to image using a small number of values – This allows us to think of the images as points in a lower-

dimensional space – We’ll examine one common approach: Principal Components

Analysis. 30e.g.picturesofyourfacefromdifferentanglesandwithdifferentlighting:theiractualpixelvaluescanbe

dramaticallydifferentbutthey’revisuallysimilarinmanywaystooureyes.Howcanwecapturethissimilaritybyrepresentingimagesinalower-dimensionalspace?

Page 31: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Principal component analysis (PCA)• Basic idea: given a set of points in a multi-

dimensional space, we wish to find the linear subspace (line, plane, etc.) that best fits those points.

31

• If we want to specify a point x with just one number (instead of two), we can specify the closest point to x on the line described by the first principal component (i.e., project x onto that line).

• In a higher dimensional space, we might specify the point lying closest to x on a plane specified by the first two principal components.

Firstprincipalcomponent

Secondprincipalcomponent

TheideaofPCAistofindthelinearsubspacesthatbestfityourhighdimensionaldataandthenprojectyourdataontothosesubspaces.Thesesubspacesarethe“principalcomponents”—thedirectionsinwhichyourdatavariesthemost.Thisgivesyouawaytorepresentyourdatainmuchfewerdimensionswhilekeepingthedistinctpointsasseparateaspossible.Keepingthepointsasseparateaspossiblemeansthatyourrepresentationstillcapturesasmuchoftheoriginalinformationaspossible.

Page 32: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Principal component analysis (PCA)• How do we pick the principal components?

– First subtract off the mean value of the points, so that the points are centered around the origin.

– The first principal component is chosen to minimize the sum squared distances of the points to the line it specifies. This is equivalent to picking the line that maximizes the variance of the full set of points after projection onto that line.

– The kth principal component is calculated the same way, but required to be orthogonal to previous principal components

32

Firstprincipalcomponent

Secondprincipalcomponent

Maximizingvarianceafterprojection=keepingthepointsasspreadoutaspossibleafterprojectingontotheline.

PCAissometimescalledSVD(singularvaluedecomposition)

Howmanyprincipalcomponentsshouldyouusetosummarizeadataset?It’sabitofajudgementcall.Thisanalysiswillalsotellyouhowmuchofthedataisexplainedbyeachprincipalcomponent—bylookingathowmuchvarianceisleftunaccountedfor—andoftenyouwillseethat80-90%ofvarianceiscapturedbythefirst3to8principalcomponents

Page 33: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Example: face recognition• A popular face recognition algorithm relies on PCA

– Take a large set of face images (centered, frontal views) – Calculate the first few principal components – Approximate each new face image as a sum of these first few principal

components (each multiplied by some coefficient). – Classify faces by comparing these coefficients to those of the original face

images

33

Originalimages Principalcomponents(viewedasimages)

hop://www.pages.drexel.edu/~sis26/Eigenface%20Tutorial.htm

Eachprincipalcomponentisavectorinthesamehighdimensionalimagespace,soitcanbeviewedasanimagetoo.

Whenafacepictureisrepresentedaspointsintheprincipalcomponentspace,picturesofthesameperson’sfacewilltendtoclustertogether,allowingyoutoidentifypeople’sfaces.

Page 34: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Practical image processing tips

34

Page 35: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Practical image processing tips (Thanks to Leo Kesselman)

• When viewing an image, you might need to scale all the intensity values up or down so that it doesn’t appear all black or all white

• You might also need to adjust the “gamma correction” to get the image to look right – This applies a nonlinear (but monotonically increasing)

function to each pixel value

35

You’renotresponsibleforthismaterial,butyoumayfindituseful

ThiscomesfromthefactthatthesamegreyvaluewilllookdifferentondifferentmonitorsorTVscreens,sotherearestandardwaystoadjustthegammavaluetocorrectforthis.

Page 36: lecture 11 image processing 2017 1 with notes · Representations of an image • Recall that we can think of a grayscale image as: – A function of two variables (x and y) – A

Next quarter: CS/CME/Biophys/BMI 371 “Computational biology in four dimensions”

• I’m teaching a course next quarter that complements this one

• Similar topic area, but with a focus on current cutting-edge research – Focus is on reading, presentation, discussion, and

critique of published papers

36