1Ellen L. Walker ImageJ Java image processing tool from NIH Reads / writes a large variety of...

19
1 Ellen L. Walker ImageJ Java image processing tool from NIH http://rsbweb.nih.gov/ij/ Reads / writes a large variety of images Many image processing operations are implemented Good rapid prototyping / testing tool Includes the ability to write your own plugins Convenient way to implement your own algorithms, using their image class and i/o methods

Transcript of 1Ellen L. Walker ImageJ Java image processing tool from NIH Reads / writes a large variety of...

Page 1: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

1 Ellen L. Walker

ImageJ

Java image processing tool from NIH

http://rsbweb.nih.gov/ij/

Reads / writes a large variety of images

Many image processing operations are implemented

Good rapid prototyping / testing tool

Includes the ability to write your own plugins

Convenient way to implement your own algorithms, using their image class and i/o methods

Page 2: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

2 Ellen L. Walker

Point Processes

Pixel by pixel transformation

Output pixel depends only on corresponding input pixel

Examples:

Out(r,c) = In(r,c) * 1.25

Out(r,c) = In(r,c) + 25

Out(r,c) = (In(r,c))2

Page 3: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

3 Ellen L. Walker

Linear Transformations

Out(r,c) = In(r,c) * gain + bias

Gain controls contrast

Bias controls brightness

Location dependent:

Out(r,c) = In(r,c) * gain(r,c) + bias(r,c)

E.g. “sky darkening filter”

Linear Blend

Out(r,c) = (lambda) * In1(r,c) + (1-lambda) * In2(r,c)

If In1 and In2 are images, a sequence of these from lambda = 0 to lambda=1 is an image dissolve

Page 4: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

4 Ellen L. Walker

Histogram

An image histogram counts the number of pixels at each brightness.

Color images have 3 histograms (red, green, blue)

0

1

2

3

4

5

6

7

0 1 2 3

Series2

Page 5: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

5 Ellen L. Walker

Information in Histogram

Contrast (variation in brightness)

Are bars spread over the whole range?

Foreground vs. background color

Are there two separate “peaks” with a valley between?

Page 6: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

6 Ellen L. Walker

Applications of Histogram

Thresholding

Find a value that separates foreground / background values

Look for a “valley” between two peaks (may or may not be what you need)

Contrast enhancement

Histogram equalization – spread the data as evenly through the histogram as possible

Goal: wide, flat histogram

Page 7: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

7 Ellen L. Walker

Example: Histogram Equalization

Original

Modified

Page 8: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

8 Ellen L. Walker

Algorithm: Histogram Equalization

Find cumulative distribution

For each intensity I, c(I) = # pixels <= I

Code:C[0]=Hist[0];For(greylevel =1; greylevel < max; greylevel++){ C[greylevel] = Hist[greylevel] + C[greylevel-1];

C[greylevel] = C[greylevel] / (double)(rows*cols); }

c(I) =1

Nh(i) = c(I −1) +

1

Ni=0

I

∑ h(I)

Page 9: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

9 Ellen L. Walker

Algorithm: Histogram Equalization

Use C(I) as a lookup table to determine the final value of each pixel.

Since C(I) ranges from 0 to 1 (why?), multiply C(I) by the max pixel value to get the output value

Code:

For(r=0;r<rows;r++)

for(c=0;c<cols;c++)

out[r][c] = C[(in[r][c])]*MAX;

Page 10: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

10 Ellen L. Walker

Locally Adaptive Histogram Equalization

Instead of doing histogram equalization using the whole image, compute the distribution for a moving window around the given pixel.

Avoids effect of bright light at one corner washing out everything in the image.

Page 11: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

11 Ellen L. Walker

Image Neighborhoods

Neighborhoods can be defined for each pixel

The two most common neighborhoods

4-neighborhood

8-neighborhood

NW E

S

Page 12: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

12 Ellen L. Walker

Applying a Mask

Mask is a set of relative pixel positions. One is designated the origin (0,0) - usually at center

Each mask element is weighted

To apply the mask, put the origin pixel over the image pixel and multiply weights by the pixels under them, then add up all the values.

Usually this is repeated for every pixel in the image . Assumptions must be made for pixels near the edge of the image.

Page 13: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

13 Ellen L. Walker

Mask application example

Mask = 1 1 1

Apply to every pixel in image:

0 0 0 0 1

0 0 0 1 1

0 0 1 1 1

0 1 1 1 1

1 1 1 1 1

Result is

0 0 0 1 1

0 0 1 2 2

0 1 2 3 2

1 2 3 3 2

2 3 3 3 2

Boundary pixels are gray

Page 14: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

14 Ellen L. Walker

Mathematical Representation of Mask Operations

Equation from Chapter 3

g is the output image

f is the input image

h is the mask (also called kernel)

Short form (convolution operator)

g(i, j) = f (i + k, j + l)h(k, l)k,l

g = f ⊗ h

Page 15: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

15 Ellen L. Walker

Masks that "blur"

"Box mask" - every pixel gets the average of its neighborhood

1 1 1 After computing, divide by 9 (mask sum)

1 1 1 to keep image from getting too bright

1 1 1

"Weighted average" - divide by 16 after application

1 2 1

2 4 2

1 2 1

Page 16: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

16 Ellen L. Walker

Why blur?

Avoid effects of small random noise (“salt and pepper”)

Remove small features to emphasize larger ones

Bigger masks blur more / remove larger features

Sequence of masks generates sequence of increasingly blurred images (useful for some matching algorithms)

First step in sharpening the image (!)

Sharp(x,y) =

orig(x,y) + gamma (orig(x,y) – (blur * orig(x,y)))

Page 17: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

17 Ellen L. Walker

Boundary Effects (padding)

Figure 3.12

Page 18: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

18 Ellen L. Walker

Common Masks

Figure 3.13

Page 19: 1Ellen L. Walker ImageJ Java image processing tool from NIH  Reads / writes a large variety of images Many image processing operations.

19 Ellen L. Walker

Median Filtering

Example of a non-linear filter

Replace the central pixel of a window with the median pixel of the window

Compare to box filter, which replaces with average value in the window

Tends to preserve edges (why?)