II MSC Matlab Record Final
II MSC Matlab Record Final
AIM:
To Choose two grayscale images or RGB images that you will first have to grayscale (withrgb2
gray() function) . Display original images and the same images after their QUANTIZATION with different
number of bits (1 to 8) using MATLAB.
PROCEDURE:
STEPS:
RGB = imread('peppers.png');
imshow(RGB)
I = rgb2gray(RGB);
figure
imshow(I)
threshRGB = multithresh(I,7);
threshForPlanes = zeros(3,7);
for i = 1:3
threshForPlanes(i,:) = multithresh(I(:,:,i),7);
end
value = [0 threshRGB(2:end) 255];
quantRGB = imquantize(I, threshRGB, value);
quantPlane = zeros( size(I) );
for i = 1:3value = [0 threshForPlanes(i,2:end) 255];
quantPlane(:,:,i) = imquantize(I(:,:,i),threshForPlanes(i,:),value);
end
quantPlane = uint8(quantPlane);
imshowpair(quantRGB,quantPlane,'montage')
axis off title('Full RGB Image Quantization Plane-by-Plane Quantization')
OUTPUT:
RESULT:
Thus the above program was executed successfully and output was verified.
EX NO: 2 2. Perform Histogram Equalization on a Color image using
MATLAB
DATE:
AIM:
PROCEDURE:
STEPS:
DATE: An Image.
AIM :
To Using Spatial Domain technique, write a program in MATLAB to perform
Smoothening operation in an image.
PROCEDURE:
STEPS:
1. Start the program.
2. Write the code in MATLAB R2014a.
3. To execute the image as output.
4. Stop the process.
CODING:
>> A = imread(’example.tif’
>> doc imread
>> whos A
>> imageinfo(’example.tif’)
>> imageview(’example.tif’)
>> figure, imagesc(A)
>> axis equal tight
>> figure, imshow(A,[])
>> A(222,320,:)
>> B = A(200:400,100:500,:); >> figure, imagesc(B)
>> close(fig_number)
>> close all
>> imwrite(B,’SavedImage.tif’)
>> doc imwrite
>> run_spatial_resolution
>> run_intensity_resolution
%1-D filtering
>> help conv >> c = conv(a,b)
>> run_convolution
>> help filter
Y = filter(B,A,X)
>> run_filter1D
%2-D filtering
h_size = 11; h_sigma = 5;
h = fspecial (’gaussian ’, h_size , h_sigma )
; figure , mesh ( h ) ; f = imread (’lena .jpg
’) ;
% if not grayscale , use rgb2gray () g = imfilter ( double ( f ) , h , ’replicate ’) ;
figure (’Name ’,’Original image ’) , imshow (f ,[]) figure (’Name ’,’Filtered image ’) , imshow (g
,[])
OUTPUT:
RESULT:
Thus the above program was executed successfully and output was verified.
EX NO : 4 4. 1-D FIR Filter to 2-D FIR Filter using FrequencyTransformation
Method
DATE:
AIM:
To Write a MATLAB code to transform 1-D FIR Filter to 2-D FIR Filter using
FrequencyTransformation Method. (FIR-Finite Impulse Response).
PROCEDURE:
STEPS:
1. Start the program.
2. Write the code in MATLAB R2014a.
3. To execute the image as output.
4. Stop the process.
CODING:
DATE:
AIM:
To Find the Boundaries of Objects within an image by Sobel operator method in
MATLAB
PROCEDURE:
STEPS:
1. Start the program.
2. Write the code in MATLAB R2014a.
3. To execute the image as output.
4. Stop the process.
CODING:
I = imread('coins.png');
imshow(I)
%Apply the Sobel edge detector to the unfiltered input image. Then, apply the Canny edge
detector to the unfiltered input image
BW1 = edge(I,'sobel');
BW2 =
edge(I,'canny');
%Display the filtered images side-by-side for comparison.
tiledlayout(1,2)
nexttile
imshow(BW1)
title('Sobel Filter')
nexttile
imshow(BW2)
title('Canny Filter')
OUTPUT:
RESULT:
Thus the above program was executed successfully and output was verified.
EX NO: 6 6. COMPARE THE IMAGES USING CANNY AND PREWITT
DATE: METHODS
AIM :
To Write a MATLAB program to detect the edges within the image and compare the results of both
Canny and Prewitt Methods.
PROCEDURE :
STEPS :
1. Start the program.
2. Write the code in MATLAB R2014a.
3. To execute the image as output.
4. Stop the process.
CODING:
DATE:
AIM:
To Write a program to Compress an image using Huffman coding method in MATLAB
PROCEDURE:
STEPS
1. Start the program.
2. Write the code in MATLAB R2014a.
3. To execute the image as output.
4. Stop the process.
CODING:
clear all
clc
A=imread('cameraman.tif');
A1=double(A(:));
[p,symbols]=hist(A1,unique(A1));
p=p/sum(p);
[dict,avglen] = huffmandict(symbols,p);
comp = huffmanenco(A1,dict);
OUTPUT:
RESULT:
Thus the above program was executed successfully and output was verified.
EX NO: 8 8. COMPRESS AN IMAGE USING COSINE
TRANSFORMATION METHOD
DATE:
AIM:
To Implement Discrete Cosine Transformation method to compress an image using
MATLAB.
PROCEDURE:
STEPS:
1. Start the program.
2. Write the code in MATLAB R2014a.
3. To execute the image as output.
4. Stop the process.
CODING:
DATE: TECHNIQUE
AIM:
To Write a MATLAB code for Image Segmentation to convert to a binary image to
improve the legibility of text Using thresholding technique.
PROCEDURE:
STEPS:
DATE:
AIM:
To Compute the Watershed Transform of the Segmentation function in an image at
foreground and background marker pixels using Marker-Controlled Watershed Segmentation in
MATLAB.
PROCEDURE:
STEPS:
rgb = imread('pears.png');
I = rgb2gray(rgb);
imshow(I)
text(732,501,'Image courtesy of Corel(R)',...
'FontSize',7,'HorizontalAlignment','right')
rgb = imread('pears.png');
I = rgb2gray(rgb);
imshow(I)
text(732,501,'Image courtesy of Corel(R)',...
'FontSize',7,'HorizontalAlignment','right')
L = watershed(gmag);
Lrgb = label2rgb(L);
imshow(Lrgb)
title('Watershed Transform of Gradient Magnitude')
se = strel('disk',20);
Io = imopen(I,se);
imshow(Io)
title('Opening')
Ie = imerode(I,se);
Iobr =
imreconstruct(Ie,I);
imshow(Iobr)
title('Opening-by-Reconstruction')
Ioc = imclose(Io,se);
imshow(Ioc)
title('Opening-Closing')
Iobrd =
imdilate(Iobr,se);
Iobrcbr = imreconstruct(imcomplement(Iobrd),imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
imshow(Iobrcbr)
title('Opening-Closing by Reconstruction')
fgm = imregionalmax(Iobrcbr);
imshow(fgm)
title('Regional Maxima of Opening-Closing by Reconstruction')
I2 = labeloverlay(I,fgm);
imshow(I2)
title('Regional Maxima Superimposed on Original Image')
se2 = strel(ones(5,5));
fgm2 = imclose(fgm,se2);
fgm3 = imerode(fgm2,se2);
fgm4 = bwareaopen(fgm3,20);
I3 = labeloverlay(I,fgm4);
imshow(I3)
title('Modified Regional Maxima Superimposed on Original Image')
bw = imbinarize(Iobrcbr);
imshow(bw)
title('Thresholded Opening-Closing by Reconstruction')
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
imshow(bgm)
title('Watershed Ridge Lines')
gmag2 = imimposemin(gmag, bgm |
fgm4); L = watershed(gmag2);
labels = imdilate(L==0,ones(3,3)) + 2*bgm + 3*fgm4;
I4 = labeloverlay(I,labels);
imshow(I4)
title('Markers and Object Boundaries Superimposed on Original Image')
Lrgb = label2rgb(L,'jet','w','shuffle');
imshow(Lrgb)
title('Colored Watershed Label
Matrix') figure
imshow(I)
hold on
himage = imshow(Lrgb);
himage.AlphaData = 0.3;
title('Colored Labels Superimposed Transparently on Original Image')
OUTPUT:
RESULT:
Thus the above program was executed successfully and output was verified.