Top Banner
Pixel Operations 4c8 Dr. David Corrigan
26

ho2_PixelOps_2013

Apr 02, 2018

Download

Documents

pavan_bmkr
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 1/26

Pixel Operations

4c8

Dr. David Corrigan

Page 2: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 2/26

Pixel Operations

• This handout looks at the most basic type of image processingapplications.

• These are simple point-wise operations of the form:

, = ((,)) 

 – I(h,k) is the input image

 – g(h,k) if the output

 – (.) is some image processing function

• In a point-wise operation the output at (h,k) is dependent only onthe value of the input (h,k) and not on the value of the input oroutput at any other location.

• These types of operations are used mainly for image enhancement.

Page 3: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 3/26

Matlab

• Images are represented as a matrix

• So G = 2.0 * I multiplies each pixel intensity by 2

and G = I + 10 increases the brightness by 2.

• Point wise operations are fast and easy to implement inhardware.

),(),(),(

),(),(),(

),(),(),(

 M  N  I  N  I  N  I 

 M  I  I  I 

 M  I  I  I 

 I 

21

22212

12111

Page 4: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 4/26

Image Histograms

• Records the number of pixels that have a particularintensity value

• Typically displayed as a plot of frequency v intensity

• Sometimes normalised so all the frequencies sum to 1

(ie. an approximation of the pdf of image intensities)• Colour images have 3D histograms but it is more

common to use separate histograms for each colourchannel.

Summaries where most of the pixels are so is useful fordesigning image enhancement operations

• Matlab function hist() or imhist() 

Page 5: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 5/26

Image Histograms

Y

U

V

Page 6: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 6/26

Image Histograms

Bin Width = 1 Bin Width = 4 Bin Width = 20

It is also common to increase the bin width.

Each frequency represents the number of 

pels in a particular range of intensities.

Page 7: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 7/26

Contrast Enhancement & Clipping

• used when you want to alter contrast or brightness of an image.

, =

0 , < min

, + min < , < max255 , > max 

 – m defines the alteration to the contrast.

 – c defines a global brightness change.

 –

min and

max

 define the range for clipping.

• Clipping is necessary to ensure that all intensities in the output stayinside the valid range (ie. when min = 0 and max = 255) but canalso be used to eliminate contrast in very bright and dark regions.(ie. when min > 0 and max < 255)

Page 8: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 8/26

Contrast Enhancement & Clipping

min intensity = 12 max intensity = 191

intensities fit full range

Page 9: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 9/26

Gamma Correction

• Gamma Correction is a non-linear modification of image contrast.

, = ,  

• If  < 1 the contrast in the dark regions is increasedand the contrast in the bright areas is increased

• The opposite occurs if 

> 1 

• Gamma Correction avoids the need for clipping sosome contrast can be maintained in the dark/brightregions.

Page 10: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 10/26

Histogram Equalisation

• An automatic technique for imageenhancement (no parameter choice required).

• However, results are unpredictable and may

look worse.• The idea is to alter the intensities so that the

histogram is as flat as possible.

•If the histogram contains a lot of pixels in anarrow range, it should be stretched out alongthe intensity range.

Page 11: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 11/26

Histogram Equalisation1 2 3 4 5 6 7 8

1 7 21 35 35 21 7 1

16 16 16 16 16 16 16 16

Levels i

H(i)

Target H(i)m

To have 16 pels at intensity 1,take all from I=1,2 and 8 from I = 3 and map onto intensity 1

because H(1) + H(2)+ 8 = 16

To have 16 pels at intensity 2Take remainder (21-8)=13 at level 3, add to 3 from level 4

So intensity mapping is 1,2,3 -> 1; 3,4 ->2 etc etc

Page 12: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 12/26

Histogram Equalisation

Histogram

Cumulative Histogram(scaled to fit axes)

0

1

Page 13: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 13/26

Histogram Equalisation

• A problem arises because most bins will mappedonto more than one output bins. It is difficult todo this consistently.

• Instead the cumulative histogram is used todesign the mapping. Again the idea is to matchthe cumulative histogram to a target cumulativehistogram.

• The target cumulative histogram is a straight line,

having a slope of 1/255, a max of 1 and a min of 0. This corresponds to a flat histogram.

• Matlab function histeq()

Page 14: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 14/26

Hist. Equalisation with CuF1 2 3 4 5 6 7 8

1 7 21 35 35 21 7 1

1 8 29 64 99 120 127 128

16 16 16 16 16 16 16 16

16 32 48 64 80 96 112 128

Levels i

H(i)

Target H(i)m

CuF(i)

Target CuF(i)m

Match Bins of Cumulative Histogram to theclosest bin in the target.

Page 15: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 15/26

Hist. Equalisation with CuF1 2 3 4 5 6 7 8

1 7 21 35 35 21 7 1

1 8 29 64 99 120 127 128

16 16 16 16 16 16 16 16

16 32 48 64 80 96 112 128

Levels i

H(i)

Target H(i)m

CuF(i)

Target CuF(i)m

Resultingtransformation

1 2 3 4 5 6 7 8

1 1 2 4 6 7 8 8

Page 16: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 16/26

Hist. Equalisation with CuF1 2 3 4 5 6 7 8

1 7 21 35 35 21 7 1

1 8 29 64 99 120 127 128

16 16 16 16 16 16 16 16

16 32 48 64 80 96 112 128

8 21 0 35 0 35 21 8

8 29 29 64 64 99 120 128

Levels i

H(i)

Output H(i)

CuF(i)

Output CuF(i)

Target H(i)

Target CuF(i)

Page 17: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 17/26

Histogram Equalisation

Matlabimadjdemo

Try it

Page 18: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 18/26

Histogram EqualisationNotice how the transformationbetween input and output relatesto the cumulative histogram of the

input.

Page 19: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 19/26

Basic Segmentation (Thresholding)

• Sometimes it is required to extract a part of an image which

contains all the relevant in formation.

Eg. We might want to isolate the

table to do some further analysis.

If the information is contained in a

limited band we can define a simplethresholding operation to segment

the image in two.

, = 0 , < 2 5 5 < , < 0 , >  

We choose

and

so that the part of 

the image he want fits inside this range.

Page 20: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 20/26

Intensity Based Segmentation

Histogram of Hue

Peak Corresponding toTable

Segmented Table = 100, = 110 Extracted Table

Page 21: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 21/26

Intensity Based Segmentation

• The previous result can beimproved by alsoincorporating a threshold onsaturation

• The condition for the table is

now > 100 & < 110& > 128  Histogram of Saturation

Grayscale Representation

of Saturation Segmented Table

Page 22: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 22/26

Intensity Based Segmentation

Segmentation with Hue aloneSegmentation using Hue andSaturation

Page 23: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 23/26

Matlab Implementation

• Read the picture from file (eg. pic =imread(‘pool.jpg’);) – pic is a × × 3 array storing the image in rgb format

 – pic(:,:,1) stores the red channel, pic(:,:,2) storesthe green channel and pic(:,:,3) stores the blue channel.

• Convert the image to the hsv and extract the hue andsaturation channels colour space

hsv = rgb2hsv(pic);hue = hsv(:,:,1);

sat = hsv(:,:,2);

Page 24: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 24/26

Matlab Implementation

• Now we can define the segmentation operation

mask = ((hue>100)&(hue<110)&(sat>128));

• To see the part of the image that has been segmented we create anew images as follows

new_pic(:,:,1) = pic(:,:,1).*mask;

new_pic(:,:,2) = pic(:,:,2).*mask;

new_pic(:,:,3) = pic(:,:,3).*mask;

 – These lines create an image that is the same as the originalimage in the area of the table and is black in the background.

Page 25: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 25/26

Matlab Implementation

• People unfamiliar with Matlab get confused by the last part. In C++ itwould be an if/else statement inside a for loop … 

for(int x = 0; x<width; x++){

for(int y = 0; y<height; y++){

for(int chan = 0; chan < 3; chan++){if(mask[x][y]!=0)

new_pic[x][y][chan]=pic[x][y][chan];

else

new_pic[x][y][chan]= 0;

}}

}

Page 26: ho2_PixelOps_2013

7/27/2019 ho2_PixelOps_2013

http://slidepdf.com/reader/full/ho2pixelops2013 26/26

Lab 1

• The first lab will get you to perform some of these pixel opsinside matlab. The segmentation code will help, however itis not complete!

In particular pay particular attention to the scaling of eachcolour channel – above we assumed that the hue channel was scaled between 0

and 360 and the saturation channel was scaled between 0 and255. This will not be the case by default.

• You will also have to learn what the best data type to use isint, float etc. You will also have to display your results asimages and perhaps write them as files.