Académique Documents
Professionnel Documents
Culture Documents
4c8
Pixel Operations
This handout looks at the most basic type of image processing applications. 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 on the value of the input (h,k) and not on the value of the input or output at any other location. These types of operations are used mainly for image enhancement.
Matlab
Images are represented as a matrix
I (1,1) I (1, 2) I ( 2,1) I ( 2, 2) I I ( N ,1) I ( N , 2) I (1, M ) I ( 2, M ) I ( N , M )
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 in hardware.
Image Histograms
Records the number of pixels that have a particular intensity 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 colour channel. Summaries where most of the pixels are so is useful for designing image enhancement operations Matlab function hist() or imhist()
Image Histograms
Y
Image Histograms
It is also common to increase the bin width. Each frequency represents the number of pels in a particular range of intensities.
Bin Width = 1
Bin Width = 4
Bin Width = 20
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 stay inside the valid range (ie. when min = 0 and max = 255) but can also be used to eliminate contrast in very bright and dark regions. (ie. when min > 0 and max < 255)
Gamma Correction
Gamma Correction is a non-linear modification of image contrast. , = ,
If < 1 the contrast in the dark regions is increased and the contrast in the bright areas is increased The opposite occurs if > 1 Gamma Correction avoids the need for clipping so some contrast can be maintained in the dark/bright regions.
Histogram Equalisation
An automatic technique for image enhancement (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 a narrow range, it should be stretched out along the intensity range.
Histogram Equalisation
Levels i H(i)
1 1 16 2 7 16 3 21 16 4 35 16 5 35 16 6 21 16 7 7 16 8 1 16
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 2 Take 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
Histogram Equalisation
Cumulative Histogram (scaled to fit axes)
Histogram
Histogram Equalisation
A problem arises because most bins will mapped onto more than one output bins. It is difficult to do this consistently. Instead the cumulative histogram is used to design the mapping. Again the idea is to match the cumulative histogram to a target cumulative histogram. 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()
CuF(i)
Target H(i) m Target CuF(i) m
16
16
16
32
16
48
16
64
16
80
16
96
16
112
16
128
CuF(i)
Target H(i) m Target CuF(i) m Resulting transformation
16
16 1 1
16
32 2 1
16
48 3 2
16
64 4 4
16
80 5 6
16
96 6 7
16
112 7 8
16
128 8 8
CuF(i)
Target H(i) Target CuF(i) Output H(i) Output CuF(i)
16
16 8 8
16
32 21 29
16
48 0 29
16
64 35 64
16
80 0 64
16
96 35 99
16
112 21 120
16
128 8 128
Histogram Equalisation
Histogram Equalisation
Notice how the transformation between input and output relates to the cumulative histogram of the input.
We choose 1 and 2 so that the part of the image he want fits inside this range.
Histogram of Hue
Extracted Table
Histogram of Saturation
Segmented Table
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) stores the green channel and pic(:,:,3) stores the blue channel.
Convert the image to the hsv and extract the hue and saturation channels colour space
hsv = rgb2hsv(pic); hue = hsv(:,:,1); sat = hsv(:,:,2);
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 a new 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 original image in the area of the table and is black in the background.
Matlab Implementation
People unfamiliar with Matlab get confused by the last part. In C++ it would 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; } } }
Lab 1
The first lab will get you to perform some of these pixel ops inside matlab. The segmentation code will help, however it is not complete! In particular pay particular attention to the scaling of each colour channel
above we assumed that the hue channel was scaled between 0 and 360 and the saturation channel was scaled between 0 and 255. This will not be the case by default.
You will also have to learn what the best data type to use is int, float etc. You will also have to display your results as images and perhaps write them as files.