The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Sunday, May 12, 2013

Creating the Negative of an Original Image



negLenna = double(Lenna);
negLennaScale = 1.0/max(negLenna(:));
negLenna = 1 - negLenna*negLennaScale;
figure;
imshow(negLenna)

Implementing Edge Detection Techniques to an Original Image



Lenna = imread('Lenna2.jpg');

figure;   SobLenna = edge(Lenna, 'sobel', 0.055, 'horizontal');
subplot(1,3,1);  imshow(SobLenna); xlabel('Horizontal');
SobLenna = edge(Lenna, 'sobel', 0.055, 'vertical'); 
subplot(1,3,2);  imshow(SobLenna); xlabel('Vertical'); title('Sobel Edge Detection');
SobLenna = edge(Lenna, 'sobel', 0.055, 'both');
subplot(1,3,3);  imshow(SobLenna); xlabel('Both');

figure;   PreLenna = edge(Lenna, 'prewitt', 0.055, 'horizontal');
subplot(1,3,1);  imshow(PreLenna); xlabel('Horizontal');
PreLenna = edge(Lenna, 'prewitt', 0.055, 'vertical'); 
subplot(1,3,2);  imshow(PreLenna); xlabel('Vertical'); title('Prewitt Edge Detection');
PreLenna = edge(Lenna, 'prewitt', 0.055, 'both');
subplot(1,3,3);  imshow(PreLenna); xlabel('Both');

figure;   RobLenna = edge(Lenna, 'roberts');
subplot(1,3,1);  imshow(RobLenna); xlabel('With Default Threshold');
RobLenna = edge(Lenna, 'roberts', 0.055);
subplot(1,3,2);  imshow(RobLenna); xlabel('Threshold = 0.055'); title('Roberts Edge Detection');
RobLenna = edge(Lenna, 'roberts', 0.1);
subplot(1,3,3);  imshow(RobLenna); xlabel('Threshold = 0.1');

figure;   LogLenna = edge(Lenna, 'log');
subplot(1,3,1);  imshow(LogLenna); xlabel('With Default Threshold & Sigma');
LogLenna = edge(Lenna, 'log', 0.0055);
subplot(1,3,2);  imshow(LogLenna); xlabel('Threshold = 0.0055 & Default Sigma');
title('Laplacian of Gaussian Edge Detection');
LogLenna = edge(Lenna, 'log', 0.0055, 1.5);
subplot(1,3,3);  imshow(LogLenna); xlabel('Threshold = 0.0055 & Sigma = 1.5');

figure;   CanLenna = edge(Lenna, 'canny');
subplot(1,3,1);  imshow(CanLenna); xlabel('With Default Threshold & Sigma');
CanLenna = edge(Lenna, 'canny', 0.155);
subplot(1,3,2);  imshow(CanLenna); xlabel('Threshold = 0.155 & Default Sigma');
title('Canny Edge Detection');
CanLenna = edge(Lenna, 'canny', 0.155, 1.25);
subplot(1,3,3);  imshow(CanLenna); xlabel('Threshold = 0.155 & Sigma = 1.25');

Removing Noise from a Noisy Corrupted Image using various Filtering Techniques



Lenna = imread('lenna2.jpg');
NoiseLenna = imnoise(Lenna,'salt & pepper',0.02);

GF1 = fspecial('gaussian',[3 3],0.5);
GF2 = fspecial('gaussian',[5 5],0.5);
GF3 = fspecial('gaussian',[7 7],0.5);

AV1 = [1 1 1;
            1 1 1;
            1 1 1]/9;

AV2 = [1 1 1 1 1;
            1 1 1 1 1;
            1 1 1 1 1;
            1 1 1 1 1;      
            1 1 1 1 1]/25;

AV3 = [1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;      
            1 1 1 1 1 1 1]/49;
  
GaussLenna = imfilter(NoiseLenna,GF1);
subplot(3,4,1);  imshow(GaussLenna);  ylabel('3x3'); title('Gaussian Filter');
GaussLenna = imfilter(NoiseLenna,GF2);
subplot(3,4,5);  imshow(GaussLenna);  ylabel('5x5');
GaussLenna = imfilter(NoiseLenna,GF3);
subplot(3,4,9);  imshow(GaussLenna);  ylabel('7x7');

AvgLenna = imfilter(NoiseLenna,AV1); 
subplot(3,4,2);  imshow(AvgLenna);  title('Averaging Filter');
AvgLenna = imfilter(NoiseLenna,AV2);
subplot(3,4,6);  imshow(AvgLenna);
AvgLenna = imfilter(NoiseLenna,AV3);
subplot(3,4,10);  imshow(AvgLenna);

MedLenna = medfilt2(NoiseLenna,[3 3]); 
subplot(3,4,3);  imshow(MedLenna);  title('Median Filter');
MedLenna = medfilt2(NoiseLenna,[5 5]);
subplot(3,4,7);  imshow(MedLenna);
MedLenna = medfilt2(NoiseLenna,[7 7]);
subplot(3,4,11);  imshow(MedLenna);

OrdLenna = ordfilt2(NoiseLenna,5,ones(3,3)); 
subplot(3,4,4);  imshow(OrdLenna);  title('Ordered Filter');
OrdLenna = ordfilt2(NoiseLenna,5,ones(5,5));
subplot(3,4,8);  imshow(OrdLenna);
OrdLenna = ordfilt2(NoiseLenna,5,ones(7,7));
subplot(3,4,12);  imshow(OrdLenna);

Adding Noise to an Original Image


 Lenna = imread('Lenna2.jpg');
 SPNoiseLenna = imnoise(Lenna,'salt & pepper',0.07);
 GNoiseLenna = imnoise(Lenna,'gaussian',0.01,0.005);
 PNoiseLenna = imnoise(Lenna,'poisson');
 SNoiseLenna = imnoise(Lenna,'speckle',0.06);
 subplot(2,2,1); imshow(SPNoiseLenna);  title('Salt & Pepper Noise');
 subplot(2,2,2); imshow(GNoiseLenna);   title('Gaussian Noise');
 subplot(2,2,3); imshow(PNoiseLenna);   title('Poisson Noise');
 subplot(2,2,4); imshow(SNoiseLenna);   title('Speckle Noise');

Finding Out the Fourier and Inverse Fourier Transform of an Image


A = [ 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0;
         0 0 0 1 1 0 0 0;
         0 0 0 1 1 0 0 0;
         0 0 0 1 1 0 0 0;
         0 0 0 1 1 0 0 0;
         0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0]

iptsetpref('ImshowTruesize','manual') figure;
subplot(3,2,1); imshow(A); title('Original Image');
subplot(3,2,2); mesh(A); title('Mesh Plot of Original Image');

B = fft2(A);
subplot(3,2,3); imshow(B); title('2-D FFT of Original Image');
subplot(3,2,4); mesh(B); title('Mesh Plot of 2-D FFT');

C = ifft2(B);
subplot(3,2,5); imshow(C); title('Inv 2-D FFT of Above Image');
subplot(3,2,6); mesh(C); title('Mesh Plot of Inv 2-D FFT');

Converting an Image into Grayscale


Lenna = imread('lenna.png');
GrayLenna = rgb2gray(Lenna);                                                  
imshow(GrayLenna)

Loading and Displaying an Image


Lenna = imread('lenna.png');
imshow(Lenna)