Tuesday, April 3, 2012

[Lab03] Intensity Transformation and Spatial Filter Part 1

Untitled Document


Intensity Transformation Functions


Intensity transformation involves contrast manipulation and thresholding. An application of intensity transformation is to increase the contrast between certain intensity values so that we can the information that we seek is more visible and clear.

Making changes in the intensity is done through Intensity Transformation Functions. The four main intensity transformation functions are:
  • Photographic Negative
  • Gamma Transformation
  • Logarithmic Transformation
  • Contrast-stretching Transformation


Photographic negative


To use Photographic Negative, use MATLAB function called imcomplement . With this transformation, the true black become true white and vice versa. It is suitable when the black areas are dominant in size. Below are the codes that implements photographic negative and example of photographic negative images.

>> I = imread('cat.jpg');
>> imshow(I)
>> J=imcomplement(I);
>> figure,imshow(J)


The following plots the photographic negative.



Gamma Transformation 


To use Gamma Transformation, use MATLAB function called imadjust. The syntax of this function is:

J = imadjust(f,[low_in high_in],[low_out high_out], gamma)
where :
f = input image
[low_in high_in],[low_out high_out] = for clipping
gamma = controls the curve


Values for low_in, high_in, low_out, and high_out must be between 0 and 1. Values below low_in are clipped to low_out and values above high_in are clipped to high_out. For the example below, we will use empty matrix ([]) to specify the default of [0 1].

gamma specifies the shape of the curve describing the relationship between the values in J and f. If gamma is less than 1, the mapping is weighted toward higher (brighter) output values. If gamma is greater than 1, the mapping is weighted toward lower (darker) output values. By default, gamma is set to 1 (linear mapping).

Below are the codes that implements gamma transformation and example of gamma transformation images.

>> I = imread('cat.jpg');
>> J1 = imadjust(I,[],[],3);
>> J2 = imadjust(I,[],[],1);
>> J3 = imadjust(I,[],[],0.4);
>> imshow(J1);
>> figure, imshow(J2);
>> figure, imshow(J3);




The following plots the gamma transformations with varying gamma.




Logarithmic Transformation


To use Logarithmic Transformation, use the function c*log(1+f).This transformation enhances the details (or contrast) in the darker region of an image (with lower intensity values) by expensing detail in brighter regions. In other words, it expands the values of dark pixel in an image while compressing the higher level values. The syntax of this function is :

g = c*log(1+double(f))

The higher the c, the brighter the image will appear. Any values (produced from logarithmic transformation) greater than one, are displayed as full intensity, equivalent to the value of 1. Below are the codes that implements logarithmic transformation and example of logarithmic transformation images.

>> imshow(I)
>> I2 = im2double(I);
>> J4 = 1 * log(1 + I2);
>> J5 = 2 * log(1 + I2);
>> J6 = 5 * log(1 + I2);
>> figure, imshow(J4)
>> figure, imshow(J5)
>> figure, imshow(J6)




The following plots the logarithmic transformations with varying C.


Contrast-Stretching Transformation


Contrast-Stretching Transformation (also called Piecewise-Linear Transformation) stretches gray-level ranges where we desire more information. This transformation increases the contrast between the darks and the lights. In simple words, the dark becomes darker and the light becomes brighter. To use this transformation, we use the function as below:

g = (1./(1+(m./(double(f)+eps)).^ E)


where:
E = slope function
m = mid-line of switching from dark value to light value
eps = MATLAB constant; distance between 1.0 and the next largest number in double-precision floating point [2^(-52)]


            Below are the codes that use contrast-stretching transformation. The mean of the image intensities as m value and varies the value of E. The higher the value of E, the function becomes more like a thresholding function, which results the image is more black and white than grayscale.

>> I=imread('cat.jpg');
>> I2=im2double(I);
>> m=mean2(I2)
>> contrast1 = 1./(1 + (m ./(I2 + eps )).^4);
>> contrast2 = 1./(1 + (m ./(I2 + eps )).^5);
>> contrast3 = 1./(1 + (m ./(I2 + eps )).^10);
>> contrast4 = 1./(1 + (m ./(I2 + eps )).^-5);
>> contrast5 = 1./(1 + (m ./(I2 + eps )).^-1);
>> figure, imshow(I2)
>> figure, imshow(contrast1)
>> figure, imshow(contrast2)
>> figure, imshow(contrast3)
>> figure, imshow(contrast4)
>> figure, imshow(contrast5)





The following plots the gamma transformations with varying E.



Another contrast-stretching transformation being applied by setting the value of E and to 4 and varies the value of m. The higher the value of m, the darker the image and fewer details are showed.

>> I=imread('cat.jpg');
>> I2=im2double(I);
>> contrast6 = 1./(1 + (0.2 ./(I2 + eps )).^4);
>> contrast7 = 1./(1 + (0.5 ./(I2 + eps )).^4);
>> contrast8 = 1./(1 + (0.7 ./(I2 + eps )).^4);
>> figure, imshow(I2)
>> figure, imshow(contrast6)
>> figure, imshow(contrast7)
>> figure, imshow(contrast8)


The following plots the contrast-stretching transformations with varying m.

3 comments:

Anonymous said...

You can't use it at a tailgate party to combine drinks. The smooth body with the motor unit easily wipes clean. The loop attachment is to generate products added inside a drink smooth and blended.

my web-site; kitchenaid ksb560

Anonymous said...

If you are tired of all the trendy toys out there, this
is a classic you can't go wrong with. Almost everyone can probably recall playing with them as a child, putting together figures and taking them apart without any regard for what they were doing. It is also a must to have a player and star wars disc, right size of projector screen for the venue, multimedia projector, and remember also, do not forget good ventilation.

Take a look at my web-site - lego police

Anonymous said...

Thanks, it was so useful for me at least. I'm waiting more posts like this one from you!

Ramin