image acquisition and enhancement
TRANSCRIPT
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
1/21
REMOTE SENSING - DIGITAL IMAGE PROCESSING
WAHYU RAHMANIAR
102521604
COMPUTER PROJECT 1: IMAGE ACQUISITION AND ENHANCEMENT
1. Image Acquisition:In this image acquisition I use a picture from internet as below:
Then I try to show this image using MATLAB code as below:
We have saved Taiwan.jpg into MATLAB with variable x, so we can see the
value of each pixel in this image that has 1119x800 pixels of class uint8.
x=imread('taiwan.jpg');imagesc(x)
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
2/21
2. Image Enhancement:(1)
Contrast stretching: piecewise linear
We have to change color image into grayscale image and change the uint8 datatype into double, this is the result and the histogram of the original picture:
% Piecewise LinearA=imread('taiwan.jpg');imagesc(A)
%colormap(gray)A=rgb2gray(A);A1=double(A);sqrt(A1(1:5,1:5))% histogramx=0:255;[y,x]=hist(double(A),x);plot(y)imagesc(A)A=double(A);% original image[y,x]=hist(A(:),x);figure, subplot(2,1,1), imagesc(A), colormap(gray)
subplot(2,1,2), bar(x,y)% histogram for each column[y1,x]=hist(double(A),x);plot(y1)% piecewise linearimagesc(A
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
3/21
This is the result using piecewise linear to enhancement image contrast, the image
look brighter than the original, because the intensity of higher value pixel (more than
200) is increased and intensity of lower pixel (less than 200) is decreased:
When the distribution of a histogram in an image is bi or tri modal, an analyst maystretch certain values of the histogram for increased enhancement in selected areas.
This method of contrast enhancement is called a piecewise linear contrast stretch. A
piecewise linear contrast enhancement involves the identification of a number of
linear enhancement steps that expands the brightness ranges in the modes of the
histogram. This figure below shows the logic used in a normal linear contrast stretch
compared to a piecewise linear contrast stretch. In the piecewise stretch, a series of
small min-max stretches are set up within a single histogram. Because a piecewise
linear contrast stretch is a very powerful enhancement procedure, image analysts must
be very familiar with the modes of the histogram and the features they represent in the
real world.
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
4/21
In the normal linear contrast stretch example, the minimum and maximum values
are stretched to the values of 0 and 255 at a constant level of intensity (defined by the
black line). In the piecewise linear contrast stretch, several breakpoints are defined
that increase or decrease the contrast of the image for a given range of values. The
higher the slope, the narrower the range of values being input from the x-axis. This
results in a wider output spread for those same values and thus, increases the contrast
for that range of values. A low sloping line results in a lower contrast for the samerange of values. Notice the series of linear steps in each histogram that stretches
intervals of data at different levels of intensities.
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
5/21
(2)Mask operation
Filter (mask) applied to zooming and noise elimination is low pass filter. This
filter convolution the image (in double type) with matrix kernel [1/5 1/5 1/5 1/5 1/5],
so we can get smoothing and blur rapid region with rapid change image as below:
A=imread('taiwan.jpg');imagesc(A)title('Taiwan')%A=double(A);
A=rgb2gray(A);%colormap(gray)
% low-pass (average)M=ones(5)/25;A=double(A)B=conv2(A,M);
figureimagesc(B)colormap(gray)
B=conv2(A,M,'same');imagesc(B)colormap(gray)
title('low-pass')
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
6/21
We can remove the dark edge in the image, so we can get smoother image, and
then using additional weight in the matrix kernel we can get smooth image but more
clearly.
% remove the dark edgeC=ones(size(B));
B=conv2(A,M,'same')./conv2(C,M,'same');imagesc(B)title('low-pass')colormap(gray)C1=conv2(C,M,'same');figurecolormap(gray)imagesc(C1*255)mesh(M)
% low-pass (weighted average)f=[.05 .25 .4 .25 .05];M1=f'*f;mesh(M1)
B=conv2(A,M1,'same')./conv2(C,M1,'same');figureimagesc(B)title('low-pass weighted')colormap(gray)
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
7/21
Filter (Mask) applied to edge detection or image sharpening is high-pass filter. We
can get high pass filter by subtract the original image with low pass filter, so theimage will be sharper with edge detail.
% high-pass = original - low-passD=zeros(5);D(3,3)=1;M2=D-M1;mesh(M2)A=double(A)B=conv2(A,M2,'same')./conv2(C,M2,'same');imagesc(B)B=conv2(A,M1,'same')./conv2(C,M1,'same');F=A-B;imagesc(F)title('high-pass')
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
8/21
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
9/21
We can get high boost filter by add the original image with high pass filter. It is
often desirable to emphasize high frequency components representing the image
details (by means such as sharpening) without eliminating low frequency components
representing the basic form of the signal. In this case, the high-boost filter can be used
to enhance high frequency component while still keeping the low frequency
components as below:
% high-boost = original + high-passfigure, imagesc(A+F), colormap(gray)title('high-boost')figure, imagesc(A+0.5*F), colormap(gray)colormap(gray)
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
10/21
First, we add noise salt and pepper in the image, and then try to remove noise
using low-pass median filter. Sets pixel intensity equal to median intensity of pixels in
neighborhood, its an excellent filter for eliminating intensity spikes.
% low-pass (median filter)I = imread('taiwan.jpg');J = imnoise(I,'salt & pepper', 0.02);imagesc(I), figure, imagesc(J)title('noise')J=double(J);fori=1:240
forj=1:306temp=J(i:i+2,j:j+2);temp1=sort(temp(:));G(i,j)=temp1(5);end
endfigurecolormap(gray)imagesc(G)title('lowpass-median')
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
11/21
Technically, it is a discrete differentiation operator, computing an approximation
of the gradient of the image intensity function. At each point in the image, the result
of the Sobel operator is either the corresponding gradient vector or the norm of this
vector. The Sobel operator is based on convolving the image with a small, separable,
and integer valued filter in horizontal and vertical direction and is therefore relatively
inexpensive in terms of computations. On the other hand, the gradient approximation
that it produces is relatively crude, in particular for high frequency variations in the
image.
The operator uses two 33 kernels which areconvolved with the original image to
calculate approximations of the derivatives - one for horizontal changes, and one forvertical.
% edge detection% Sobel filtersobel1=[-1 -2 -1;0 0 0;1 2 1];sobel2=sobel1';A1=conv2(A,sobel1,'same');A2=conv2(A,sobel2,'same');figureimagesc(A1)title('sobel')colormap(gray)figureimagesc(A2)colormap(gray)imagesc(sqrt((A1).^2+(A2).^2))imagesc(abs(A1)+abs(A2))
http://en.wikipedia.org/wiki/Convolutionhttp://en.wikipedia.org/wiki/Convolution -
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
12/21
Convolution operator:
Since the Sobel kernels can be decomposed as the products of an averaging and a
differentiation kernel, they compute the gradient with smoothing. For example,
can be written as
This image below is an image with Sobel filter kernel.
The x-coordinate is defined here as increasing in the "right"-direction, and the y-
coordinate is defined as increasing in the "down"-direction. At each point in the image,
the resulting gradient approximations can be combined to give the gradient magnitude,
using:
This picture below is the result of G:
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
13/21
The operator uses two 33 kernels filter, according to Roberts, an edge detector
should have the following properties: the produced edges should be well-defined, the
background should contribute as little noise as possible, and the intensity of edgesshould correspond as close as possible to what a human would perceive. The results
of this operation will highlight changes in intensity in a diagonal direction. One of the
most appealing aspects of this operation is its simplicity; the kernel is small and
contains only integers.
% Robert filter
robert1=[0 0 0 ; 0 -1 0 ; 0 0 1];robert2=[0 0 0 ; 0 0 -1 ; 0 1 0];A1=conv2(A,robert1,'same');A2=conv2(A,robert2,'same');imagesc(A2)imagesc(A1)imagesc(abs(A1)+abs(A2))title('Robert')
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
14/21
(3)Fourier Transform
The Fourier Transform is a tool which is used to decompose an image into its sine
and cosine components. The output of the transformation represents the image in the
Fourierorfrequency domain,while the input image is thespatial domain equivalent.
In the Fourier domain image, each point represents a particular frequency contained in
the spatial domain image like the picture below:
A=imread('taiwan.jpg');A=rgb2gray(A)A=double(A);% FourierB=fft2(A);figureimagesc(A)title('fourier')colormap(gray)
% Fourier spectrumfigureimagesc(abs(B))colormap(gray)imagesc(log(abs(B)+1))C=fftshift(B);imagesc(log(abs(C)+1))title('fourier-spectrum')
http://homepages.inf.ed.ac.uk/rbf/HIPR2/freqdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/spatdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/spatdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/freqdom.htm -
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
15/21
If we apply alogarithmic transformation to the image we obtain fourier spectrum
as below:
http://homepages.inf.ed.ac.uk/rbf/HIPR2/pixlog.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/pixlog.htm -
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
16/21
The result shows that the image contains components of all frequencies, but that
their magnitude gets smaller for higher frequencies. Hence, low frequencies contain
more image information than the higher ones. The transform image also tells us that
there are two dominating directions in the Fourier image, one passing vertically and
one horizontally through the center.
(4)Histogram equalization.
Histogram Equalization is defined as equalizing the intensity distribution of an
image or flattening the intensity distribution curve. Histogram equalization is used to
improve the contrast of an image. The equalized histogram of the above image should
be ideally like the following graph.
This is the histogram of original image:
% image readI = imread('taiwan.jpg');%I = double(I);I = rgb2gray(I);J = histeq(I);imshow(I)figure, imshow(J)figure; imhist(I,255)figure; imhist(J,255)
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
17/21
This is image with histogram equalization:
This is the histogram of image after histogram equalization:
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
18/21
(5)Histogram specification with a distribution you designed.
This code purpose to enhancement image contrast with histogram specification of
Gaussian distribution like the picture below:
% image readA=imread('taiwan.jpg');imagesc(A)A=rgb2gray(A);
colormap(gray)% histogram specification (Gaussian)y1=exp(-0.5*(x-128).^2/40^2);plot(x,y1)y1=y1/sum(y1);plot(x,y1)bar(x,y1)
fori=1:256z1(i)=sum(y1(1:i));endfori=1:256[Y,m]=max(z1>z(i));
F(A==(i-1))=m;end%[y1,x]=hist(F(:),x);%figure, subplot(2,1,1), imagesc(reshape(F,256,256)),
colormap(gray)%subplot(2,1,2), bar(x,y1)imagesc(F)colormap(gray)
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
19/21
Because the gaussian distribution has high value of pixel in the center and
decrease to the left and right, so the pixel value between 100-150 will be more
contrast and the pixel value that bright or dark will be less contrast.
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
20/21
3. Color Image Enhancement
First, we change the RGB image into HSV image, the first plot show hue, the
second show saturate, and the third show value or intensity.
A=imread('taiwan.jpg');A=double(A);
% HSI color systemB=rgb2hsv(A);fori=1:3subplot(2,2,i)imagesc(B(:,:,i))endcolormap(gray)subplot(2,2,4)image(A/255)
% Mask operation on intensityfigure
M=ones(5)/25;B1=B;B1(:,:,3)=conv2(B(:,:,3),M,'same');subplot(2,2,1)imagesc(B1(:,:,3))title('intensity1')A2=hsv2rgb(B1);subplot(2,2,2)image(A2/255)title('intensity2')
-
7/24/2019 IMAGE ACQUISITION AND ENHANCEMENT
21/21
Intensity 1 show the enhancement of intensity in HSV image using convolution of
HSV image with kernel [1/5 1/5 1/5 1/5 1/5], and then change HSV into RGB image
to show the result like intensity 2. And using fourier we can get more contrast image
but low intensity as below.
% FourierD=fft2(B(:,:,3));D1=fftshift(D);[m,n]=size(D);H=zeros(size(D));
[X,Y]=meshgrid(1:n,1:m);H=sqrt((X-floor(n/2)).^2+(Y-floor(m/2)).^2)