Mip-191bm72b Lab Manual
Mip-191bm72b Lab Manual
RANGARAJAN
Dr.SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution
(AN ISO 9001:2008 CERTIFIED INSTITUTION)
(APPROVED BY AICTE, NEW DELHI & GOVT. OF TAMIL NADU AFFILIATED TO
ANNA UNIVERSITY, ACCREDITED BY NBA, NEW DELHI)
(ACCREDITED BY NAAC WITH ‘A’ GRADE)
N0.42, AVADI-VEL-TECH ROAD, CHENNAI- 600 062
2019 REGULATION
Prepared by
Ms.NITHYAKALYANI.K, M.E(Ph.D)/MTS1449
Assistant Professor
DEPARTMENT OF BIO-MEDICAL ENGINEERING
VISION
To establish teaching and research platform in medical electronics for the health and
well being of mankind
MISSION
To implement the versatile qualities acquired to a chosen career, by providing an impact for
the sustainable growth and success.
To explore their ideas in research and promoting them to be exceptionally good in meeting
the challenges of innovation and creativity.
Able to understand the mathematical and physical foundations of biomedical engineering and
1. how these are applied in the analysis of biological systems for biomedical instruments and
technological advancement for health care. (Understand)
Able to design a variety of electronic devices and software for applications including biomedical
2. instrumentation, physiological measurement, rehabilitation engineering and medical imaging &
informatics. (Design)
Able to meet desired needs within realistic constraints such as economic, environmental, social,
3. ethical, health and safety, manufacturability and sustainability. (Society, Environmental,
Sustainability)
DEPARTMENT OF BIO-MEDICAL ENGINEERING
PO1 Engage in life-long learning to recognize the latest technological changes to meet
2 the societal demands.
191BM72B MEDICAL IMAGE PROCESSING LAB LTPC
0021
COURSE OBJECTIVES:
OUTCOMES:
At the end of the course, the student should be able to:
1. Perform enhancing operations on the image using spatial filters and frequency domain
filters.
2. Use transforms and analyse the characteristics of the image.
3. Perform segmentation operations in the images.
4. Estimate theefficiency of the compression technique on the images.
5. Apply image processing technique to solve real health care problems.
191BM72B MEDICAL IMAGE PROCESSING LAB LTPC
0021
LIST OF EXPERIMENTS:
Perform enhancing
operations on the image
using spatial filters and 3 1 2 3 3 - - - - - - 1 3 - -
LAB
Estimate theefficiency of
the compression technique 3 3 3 3 3 - - - - - - 1 3 1 -
on the images.
Course Cognitiv
Course Outcome Statements Linked POs & PSOs
Outcome e Level
Perform enhancing operations
on the image using spatial PO1,PO2,PO3.PO4,PO5
CO1 K4
filters and frequency domain PSO1,PSO2
filters
Use transforms and analyse the
PO1,PO2,PO3.PO4,PO5
CO2 characteristics of the image. K3 PSO1,PSO2
Perform segmentation
PO1,PO2,PO3.PO4,PO5
CO3 operations in the images. K3
PSO1,PSO2
9 Image segmentation – Edge detection, line detection and point detection. CO3
IMAGE QUANTISATION
1) Load image.
2) Convert to gray scale image.
3) Quantize image with particular rate.
4) Display quantized image.
PROGRAMS
% IMAGE SAMPLING %
clc ;
close all;
clear all;
a=imread('Desert.jpg');
subplot(2,2,1);
imshow(a);
title('original image');
subsample=4;
s=a(1:subsample:end,1:subsample:end);
subplot(2,2,2);
imshow(s);
title('sampled image at sample rate 4');
subsample=16;
s=a(1:subsample:end,1:subsample:end);
subplot(2,2,3);
imshow(s);
title('sampled image at sample rate 16');
subsample=64;
s=a(1:subsample:end,1:subsample:end);
subplot(2,2,4);
imshow(s);
title('sampled image at sample rate 64');
% IMAGE QUANTISATION %
clc;
close all;
clear all;
a=imread('Desert.jpg');
subplot(2,2,1);
imshow(a);
title('original image');
subsample=16;
s=a(1:subsample:end,1:subsample:end);
subplot(2,2,2);
imshow(s);
title('sampled image at sample rate 4');
thresh=multithresh(s,2);
S1=imquantize(s,thresh);
rgb=label2rgb(S1);
subplot(2,2,4);
imshow(rgb);
title('Quantized image at sample rate 4');
OUTPUT :
IMAGE SAMPLING
IMAGE QUANTIZATION
RESULT :
Thus the given image is sampled and quantized at different sampling and quantization rates using
MATLAB .
EX NO :2 ANALYSIS OF SPATIAL AND INTENSITY RESOLUTION OF MRI IMAGES
DATE:
AIM
To analyze spatial and intensity resolution of given input image using MATLAB. The analyses to
perform are,
a) The effect of changing the number of gray levels on the quality of image.
b) The effect of changing spatial resolution on the quality of image
REQUIREMENTS
PC with MATLAB software.
ALGORITHM
SPATIAL RESOLUTION
1) Read the image.
2) Display the original image.
3) Convert the colour image to gray scale image.
4) Resize the grayscale image to different resolution.
5) Display images with different spatial resolution.
INTENSITY RESOLUTION
1) Load the image.
2) Display the original image.
3) Set the bits per pixel of the image.
4) Display the image with new bits per pixel.
5) Repeat the steps 3 & 4 with different bits per pixel and display the image.
PROGRAM
% SPATIAL RESOLUTION%
clc;
close all;
clear all;
a=imread('Desert.jpg'); %reads the image
subplot(3,2,1);
imshow(a); %displays the image
title('original image');
b=rgb2gray(a);
subplot(3,2,2);
imshow(b); %displays the image
title('gray image');
r1=imresize(b,[256 256]);
subplot(3,2,3);
imshow(r1); %displays the image
title('image-256x256');
r2=imresize(r1,[128 128]);
subplot(3,2,4);
imshow(r2); %displays the image
title('image-128x128');
r3=imresize(r2,[64 64]);
subplot(3,2,5);
imshow(r3); %displays the image
title('image-64x64');
r4=imresize(r3,[32 32]);
subplot(3,2,6);
imshow(r4); %displays the image
title('image-32x32');
clc;
clear all;
close all;
a= imread('Desert.jpg'); %reads the image
subplot(2,2,1);
imshow(a); %displays the image
title('8 bits per pixel-256 gray levels');
n=7;
maxvalue=(2^n)-1;
newimage=a*(maxvalue/256);
subplot(2,2,2);
imshow(newimage,[]);%displays the image
title('7 bits per pixel-128 gray levels');
n=6;
maxvalue=(2^n)-1;
newimage=a*(maxvalue/256);
subplot(2,2,3);
imshow(newimage,[]);%displays the image
title('6 bits per pixel-64 gray levels');
n=4;
maxvalue=(2^n)-1;
newimage=a*(maxvalue/256);
subplot(2,2,4);
imshow(newimage,[]);%displays the image
title('4 bits per pixel-16 gray levels');
OUTPUT:
SPATIAL RESOLUTION
INTENSITY RESOLUTION
RESULT:
Thus the spatial resolution and intensity resolution of the given image are analyzed using
MATLAB.
EX NO:3 INTENSITY TRANSFORMATION OF IMAGES
DATE:
AIM
To transform the intensity of the given image by arithmetic operations using MATLAB.
REQUIREMENTS
PC with MATLAB software.
ALGORITHM
1) Read the image.
2) Display the original image.
3) Intensity of the given image is transformed using addition, subtraction, multiplication and
division.
4) Display all intensity transformed images.
PROGRAM
% INTENSITY RESOLUTION OF IMAGES USING ARITHMETIC OPERATIONS %
clc;
clear all;
close all;
a= imread('Angel.jpg'); %reads the image
subplot(3,2,1);
imshow(a); %displays the image
title('original image');
v=a+25;
subplot(3,2,3);
imshow(v); %displays the image
title('intensity transformed image +25');
w=a-50;
subplot(3,2,4);
imshow(w); %displays the image
title('intensity transformed image -50');
x=a*50;
subplot(3,2,5);
imshow(x); %displays the image
title('intensity transformed image *50');
y=a/5;
subplot(3,2,6);
imshow(y); %displays the image
title('intensity transformed image /5');
OUTPUT:
INTENSITY TRANSFORMATION OF IMAGES
RESULT:
Thus the intensity of the given image are transformed using arithmetic operations using MATLAB
software.
AIM
To perform Discrete fourier transform and inverse discrete fourier transform of a image for
frequency domain analysis using MATLAB.
REQUIREMENTS
PC with MATLAB software.
ALGORITHM
1) Import the image.
2) Display the original image.
3) Apply FFT.
4) Shift the origin.
5) Apply IFFT for FFT shifted image.
6) Reshift the origin.
7) Apply IFFT for the reshifted image.
PROGRAM
% DFT ANALYSIS OF IMAGES %
clear all;close all;
a=imread('Desert.jpg');% IMPORT IMAGE
subplot(3,3,1);
imshow(a); %DISPLAY IMAGE
title('Imported Image');
%2D FAST FOURIER TRANSFORMATION
y= fft2(a);
subplot(3,3,2);
imshow(y);
title('FFT of the given image');
%SHIFTING OF ORIGIN
z= fftshift(y);
subplot(3,3,3);
imshow(z);
title('FFT with the shifted origin');
%INVERSE FFT
n= ifft2(z);
n1=uint8(n);
subplot(3,3,4);
imshow(n1);
title('IFFT of the shifted image');
%RESHIFTING OFTHEORIGIN
m= ifftshift(z);
subplot(3,3,5);
imshow(m);title('FFT reshifted to the original position');
%INVERSEFFT
n= ifft2(m);
n1=uint8(n);
subplot(3,3,6);
imshow(n1);
title('IFFT of the reshifted image');
OUTPUT:
DFT ANALYSIS OF THE IMAGES
RESULT :
Thus the discrete fourier transform and inverse discrete fourier transform of are applied to
the given image and displayed with the help of MATLAB software.
AIM
To perform Walsh-hadamard Transform, Discrete Cosine Transform and Haar Transform
REQUIREMENTS
PC with MATLAB software.
ALGORITHM
WALSH HADAMARD TRANSFORM
1) Read and display the image
2) Convert to 2 dimensional gray scale image
3) Apply Walsh-hadamard Transform with order 512
4) Apply inverse Walsh-hadamard Transform to transformed image
5) Repeat step 3 and 4 for order 1024
6) Display the images
HAAR TRANSFORM
1) Load and display the image
2) Apply 2 dimension Discrete Wavelet Transform in haar mode to single precision image
matrix
3) Display the image after first level degradation
4) Again apply 2 dimension Discrete Wavelet Transform to degraded image
5) Display the image after second level degradation
6) Apply 2 dimension Inverse Discrete Wavelet Transform in haar mode
7) Display Inverse wavelet transformed images
PROGRAM
% WALSH HADAMARD TRANSFORMS
close all;
imgA=imread('C:\Users\Public\Pictures\Sample Pictures\Desert.jpg');
imgA=rgb2gray(imgA);
imgA=double(imgA);
N=512;
y=fwht(imgA,N); %image is longer than N, image is truncated
subplot(2,2,1);
imshow(y);
title('Truncated 512-point discrete Walsh–Hadamard transform');
a=ifwht(double(y));
subplot(2,2,2);
imshow(uint8(a));
title('Truncated 512-point inverse discrete Walsh–Hadamard transform');
N=1024;
y=fwht(imgA,N);%image is shorter than N, image is padded with zero
subplot(2,2,3);
imshow(y);
title('Zero padded 1024-point discrete Walsh–Hadamard transform');
a=ifwht(double(y));
subplot(2,2,4);
imshow(uint8(a));
title('Zero padded 1024-point inverse discrete Walsh–Hadamard transform');
%HAAR TRANSFORMS
clc;
x=imread('C:\Users\Public\Pictures\Sample Pictures\Desert.jpg');
subplot(3,2,1);
imshow(x);
title('Orginal image');
[a b c d]=dwt2(single(x),'haar');
y=[uint8(a),b; c,d];
subplot(3,2,2);
imshow(y);
title('Image after first level degradation');
[a1 b1 c1 d1]=dwt2(a,'haar');
y1=[a1,b1; c1,d1];
y2=[uint8(y1),b; c,d];
subplot(3,2,3);
imshow(y2);
title('Image after Second level degradation');
x1=idwt2(a,b,c,d,'haar');
subplot(3,2,4);
imshow(uint8(x1));
title('First inverse wavelet transform');
x2=idwt2(a1,b1,c1,d1,'haar');
subplot(3,2,5);
imshow(uint8(x2));
title('Second inverse wavelet transform');
OUTPUT
WALSH HADAMARD TRANSFORM
HAAR TRANSFORMS
RESULT
Thus Walsh-hadamard Transform, Discrete Cosine Transform and Haar Transform are
performed using MATLAB
AIM
To perform histogram processing and basic thresholding functions for the given input image
and to apply histogram equalization on given input image.
REQUIREMENTS
PC with MATLAB software
ALGORITHM:
1) Load an image
2) Display the histogram of the loaded image
3) Enhance the contrast of the image using histogram equalization
4) Display the contrast-enhanced image
PROGRAM
close all;
a=imread('Desert.jpg');
subplot(3,3,1);
imshow(a);
title('Orginal image');
b=rgb2gray(a);
subplot(3,3,2);
imshow(b);
title('Grayscale image');
subplot(3,3,3);
imhist(b);
title('histogram of orginal image');
c=histeq(b);
subplot(3,3,4);
imshow(c);
title('Equalized image');
subplot(3,3,5);
imhist(c);
title('histogram of equalized image');
d=adapthisteq(b);
subplot(3,3,7);
imshow(d);
title('Adaptive histogram equalised image');
subplot(3,3,8);
imhist(d);
title('histogram of adaptive equalized image');
% THRESHOLDING OF IMAGE
function thresholding
global H Index;
B=imread('C:\Users\VM5606\Desktop\light1.jpg'); % Read image
subplot(2,2,1);
imshow(B); % Display
title('Original image');
V=reshape(B,[],1); % Reshape image
G=hist(V,0:255); % Histogram of the image
H=reshape(G,[],1); % Reshape image
Ind=0:255;
Index=reshape(Ind,[],1);
result=zeros(size([1 256]));
for i=0:255
[wbk,varbk]=calculate(1,i);
[wfg,varfg]=calculate(i+1,255);
result(i+1)=(wbk*varbk)+(wfg*varfg);
end
function [weight,var]=calculate(m,n)
%Weight Calculation
weight=sum(H(m:n))/sum(H);
%Mean Calculation
value=H(m:n).*Index(m:n);
total=sum(value);
mean=total/sum(H(m:n));
if(isnan(mean)==1)
mean=0;
end
%Variance calculation
value2=(Index(m:n)-mean).^2;
numer=sum(value2.*H(m:n));
var=numer/sum(H(m:n));
if(isnan(var)==1)
var=0;
end
end
end
OUTPUT
HISTOGRAM PROCESSING
RESULT
Thus Histogram thresholding functions are processed for the given input image and Histogram
equalization outputs are plotted using MATLAB successfully.
REQUIREMENTS
PC with MATLAB software
ALGORITHM
1) Read and display the image
2) Design simple filter
3) Filter the image with zero pad, replicate, symmetric and circular mode
4) Add noise to the image
5) Design special filters like Average, Unsharp, Motion blurred, Blur, Gaussian, Log, and
Laplacian
6) Filter the image using special filters and display the filtered image
PROGRAM
clc;
clear all;
close all;
im=imread('C:\Users\Public\Pictures\Sample Pictures\Light house.jpg');
subplot(3,4,1);
imshow(im);
title('Original');
h = ones(5,5)/20;
zer_pad=imfilter(im,h);
subplot(3,4,2)
imshow(zer_pad);
title('Zero-Padded')
repl=imfilter(im,h,'replicate');
subplot(3,4,3)
imshow(repl);
title('Replicate')
sym=imfilter(im,h,'symmetric');
subplot(3,4,4)
imshow(sym);
title('Symmetric')
cirl=imfilter(im,h,'circular');
subplot(3,4,5)
imshow(cirl);
title('Circular')
J = imnoise(im,'salt & pepper',0.02);
h1=fspecial('average',5); % Removal of noise by averaging
avg1=imfilter(J,h1);
subplot(3,4,6)
imshow(avg1);
title('Average');
h2=fspecial('unsharp');
unsp=imfilter(im,h2);
subplot(3,4,7)
imshow(unsp);
title('Unsharp');
h3=fspecial('motion',35,65);
motion_blur=imfilter(im,h3,'replicate');
subplot(3,4,8);
imshow(motion_blur);
title('Motion blurred');
h4=fspecial('disk',20);
blur=imfilter(im,h4);
subplot(3,4,9);
imshow(blur);
title('Blur');
h5=fspecial('gaussian',3,0.4);
gaus=imfilter(im,h5);
subplot(3,4,10);
imshow(gaus);
title('Gaussian');
h6=fspecial('log',5,0.3);
logg=imfilter(im,h6);
subplot(3,4,11);
imshow(logg);
title('Log');
h7=fspecial('laplacian',0.1);
lapl=imfilter(im,h7);
subplot(3,4,12);
imshow(lapl);
title('Laplacian');
OUTPUT
RESULT
Thus Image Enhancement process is carried out in spatial domain for an input image using
various spatial filtering techniques and corresponding outputs are plotted and analyzed.
EX NO: 8 IMAGE ENHANCEMENT- FILTERING IN FREQUENCY DOMAIN
DATE :
AIM
To perform image enhancement by filtering in frequency domain.
REQUIREMENTS
PC with MATLAB software
ALGORITHM
PROGRAM
clear all;
clc;
x1=imread('Koala.jpg');
x=rgb2gray(x1);
subplot(2,2,1);
imshow(x);
title('The given image');
% Butterworth low pass filter
fc=30;
fc2=fc*fc;
r=1;
[m,n]=size(x);
f=fft2(x);
subplot(2,2,2);
imshow(f);
title('FFT of the given image');
fs=fftshift(f);
mc=round(m/2);
nc=round(n/2);
b=zeros(m,n);
fori=1:m
for j=1:n
d=(i-mc).^2+(j-nc).^2;
b(i,j)=1/(1+((d/fc2).^(2*r)));
end
end
h=fs .* b;
% y=ifftshift(h);
y1=abs(ifft2(h));
y2=uint8(y1);
subplot(2,2,3);
imshow(y2);
title('Smoothened image using butterworthlowpass filter');
% Butterworth high pass filter
fc=1.2;
fc2=fc*fc;
fori=1:m
for j=1:n
d=(i-mc).^2+(j-nc).^2;
b(i,j)=1/(1+((fc2/d).^(2*r)));
end
end
h=fs.*b;
y1=abs(ifft2(h));
y2=uint8(y1);
subplot(2,2,4);
imshow(y2);
title('Sharpened image using butterworthhighpass filter');
OUTPUT
RESULT
The given image has been filtered using a frequency domain filter.
EX.NO: 9 IMAGE SEGMENTATION – EDGE DETECTION, LINE DETECTION
AND POINT DETECTION
DATE:
AIM:
To perform segmentation of an image by edge detection, line detection and point detection
techniques using MATLAB.
REQUIREMENTS:
PC with MATLAB software.
ALGORITHM:
EDGE DETECTION
1) Read the image from file location.
2) Convert into gray-scale image.
3) Perform edge detection of the image with Prewitt, Sobel, Canny, Roberts, Log and Zero-
cross techniques.
4) Display the result.
LINE DETECTION
1) Read the image from file location.
2) Convert into gray-scale image.
3) Perform edge detection of the image with Canny edge detection technique.
4) Detect the lines present in the image using houghline tranform.
5) Display the result.
POINT DETECTION
1) Read the image from file location.
2) Convert into gray-scale image.
3) Set threshold for the points to be detected.
4) Detect the points present in an image using detectFASTfeatures.
5) Display the result.
PROGRAM:
% EDGE DETECTION
clc;
clear all;
close all;
x= imread('C:\Users\HP\Pictures\Nature\macaw4.jpg'); % Read the image
subplot(3,3,1);
imshow(x); % Display the original image
title('Original image');
x1=rgb2gray(x); % RGB -> Gray conversion
subplot(3,3,2);
imshow(x1);
title('Grayscale image'); % Display Gray scale image
b= edge(x1,'prewitt'); % Perform Prewitt edge detection
subplot(3,3,3);
imshow(b); % Display image
title('Edge detection using Prewitt edge detector');
c= edge(x1, 'sobel'); % Perform Sobel edge detection
subplot(3,3,4);
imshow(c); % Display image
title('Edge detection using Sobel edge detector');
d= edge(x1,'canny'); % Perform Canny edge detection
subplot(3,3,5);
imshow(d); % Display image
title('Edge detection using Canny edge detector');
e= edge(x1,'roberts'); % Perform Roberts edge detection
subplot(3,3,6);
imshow(e); % Display image
title('Edge detection using Roberts edge detector');
f= edge(x1,'log'); % Perform Log edge detection
subplot(3,3,7);
imshow(f); % Display image
title('Edge detection using log edge detector');
g= edge(x1,'zerocross'); % Perform Log edge detection
subplot(3,3,8);
imshow(g); % Display image
title('Edge detection using zerocrossing');
% LINE DETECTION
clc;
clear all;
close all;
I =imread('C:\Users\VM5606\Desktop\light1.jpg'); % Read the image
I=rgb2gray(I); % RGB -> Gray scale conversion
BW = edge(I,'canny'); % Edge detection using canny
[H,T,R] = hough(BW); % Hough transform
P =houghpeaks(H,5,'threshold',ceil(0.3*max(H(:)))); % Detect Hough peaks
x = T(P(:,2)); y = R(P(:,1));
% Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(I), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len>max_len)
max_len = len;
xy_long = xy;
end
end
% Highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','blue');
legend('Line','startpoint','end point');
% POINT DETECTION ( Compatible in 2013 version )
clc;
clear all;
close all;
imgA=imread('C:\Users\VM5606\Desktop\light1.jpg'); % Read image
imgA=rgb2gray(imgA); % RGB -> Gray scale conversion
ptThresh = 0.1; % Setting threshold level
pointsA = detectFASTFeatures(imgA, 'MinContrast', ptThresh); % Detect points
figure; imshow(imgA); hold on; % Display result
plot(pointsA);
title('Detected points in A');
OUTPUT:
EDGE DETECTION
LINE DETECTION
POINT DETECTION
O/P for version 2013
RESULT:
Thus the segmentation of an image by edge detection, line detection and point detection
techniques has been performed using MATLAB.
AIM:
To perform morphological operations such as dilation, erosion, opening, closing, thinning and
thickening of images using MATLAB.
REQUIREMENTS:
PC with MATLAB software
ALGORITHM:
1) Read the image from file location.
2) Resize the image and set threshold level.
3) Convert the resized image into gray image for the threshold value.
4) Perform operations such as dilation, erosion, opening, closing, thinning and thickening in
the gray level image.
5) Display the result.
PROGRAM:
% MORPHOLOGICAL OPERATIONS
clc;
clear all;
close all;
thresh=120; % Threshold
filename= 'C:\Users\VM5606\Desktop\light1.jpg'; % The file to be read
i=imread(filename);
i=imresize(i, [256 256]); % Resize image
subplot(4,4,1);
imshow(i); % Display
title('Resized original image');
axis('square');
colormap('gray');
i1=uint8(i);
LEVEL=thresh/255.0;
i2= rgb2gray(i1);
BW = im2bw(i2,LEVEL); % Converts the intensity image I to black and white
subplot(4,4,2);
imshow(BW);
title('Gray image');
% Dilation
K3=ones(3); K5=ones(5); K7=ones(7); K9=ones(9);
B3=imdilate(BW,K3);
B5=imdilate(BW,K5);
B7=imdilate(BW,K7);
B9=imdilate(BW,K9);
subplot(4,4,3);
imshow(B3); % display
title('Dilated image to 3 pixels');
axis('square');
colormap('gray');
subplot(4,4,4);
imshow(B5); % display
title('Dilated image to 5 pixels');
axis('square');
colormap('gray');
subplot(4,4,5);
imshow(B7); % display
title('Dilated image to 7 pixels');
axis('square');
colormap('gray');
subplot(4,4,6);
imshow(B9); % display
title('Dilated image to 9 pixels');
axis('square');
colormap('gray');
% Erosion
K3=ones(3); K5=ones(5); K7=ones(7); K9=ones(9);
B3=imerode(BW,K3);
B5=imerode(BW,K5);
B7=imerode(BW,K7);
B9=imerode(BW,K9);
subplot(4,4,7);
imshow(B3); % display
title('Image erosed to 3 pixels');
axis('square');
colormap('gray');
subplot(4,4,8);
imshow(B5); % display
title('Image erosed to 5 pixels');
axis('square');
colormap('gray');
subplot(4,4,9);
imshow(B7); % display
title('Image erosed to 7 pixels');
axis('square');
colormap('gray');
subplot(4,4,10);
imshow(B9); % display
title('Image erosed to 9 pixels');
axis('square');
colormap('gray');
% Opening
op=bwmorph(BW,'open');
subplot(4,4,11);
imshow(op); % display
title('Opened image');
axis('square');
colormap('gray');
% Closing
op=bwmorph(BW,'close');
subplot(4,4,12);
imshow(op); % display
title('Closed image');
axis('square');
colormap('gray');
% Thinning
op=bwmorph(BW,'thin');
subplot(4,4,13);
imshow(op); % display
title('Thinned image');
axis('square');
colormap('gray');
% Thickening
op=bwmorph(BW,'thick');
subplot(4,4,14);
imshow(op); % display
title('Thickened image');
axis('square');
colormap('gray');
OUTPUT:
MORPHOLOGICAL PROCESSING
RESULT:
Thus the basic morphological operations such as dilation, erosion, opening, closing, thinning,
thickening of an image has been performed using MATLAB.
AIM:
To perform Region based Segmentation on an image
ALGORITHM:
PROGRAM:
function
J=regiongrowing(I,x,y,reg_maxdist) I
= im2double(imread('medtest.png'));
x=198; y=359;
J=
regiongrowing(I,x,y,0.2
); figure, imshow(I+J);
if(exist('reg_maxdist','var')==0), reg_maxdist=0.2; end
if(exist('y','var')==0)
figure
imshow(I,[]);
[y,x]=getpts;
y=round(y(1));
x=round(x(
1)); end
J = zeros(size(I)); % Output
Isizes = size(I); % Dimensions of input image
reg_mean = I(x,y); % The mean of the segmented region
reg_size = 1; % Number of pixels in region
neg_free = 10000;
neg_pos=0; neg_list =
zeros(neg_free,3);
pixdist=0;
neigb=[-1 0; 1 0; 0 -1;0 1];
while(pixdist<reg_maxdist&®_size<numel(I))
% Add new neighbors
pixels for j=1:4,
% Calculate the neighbour
coordinate xn = x +neigb(j,1); yn
= y +neigb(j,2);
% Check if neighbour is inside or outside the image
ins=(xn>=1)&&(yn>=1)&&(xn<=Isizes(1))&&(yn<=Isizes(2));
% Add neighbor if inside and not already part of the segmented area
if(ins&&(J(xn,yn)==0))
neg_pos = neg_pos+1;
neg_list(neg_pos,:) = [xn yn I(xn,yn)]; J(xn,yn)=1;
end dist = abs(neg_list(1:neg_pos,3)-
reg_mean); [pixdist, index] = min(dist);
J(x,y)=2; reg_size=reg_size+1;
% Calculate the new mean of the region
reg_mean= (reg_mean*reg_size + neg_list(index,3))/(reg_size+1);
% Save the x and y coordinates of the pixel (for the neighbour add
proccess) x = neg_list(index,1); y = neg_list(index,2);
% Remove the pixel from the neighbour (check) list
neg_list(index,:)=neg_list(neg_pos,:); neg_pos=neg_pos-1;
end
% Return the segmented area as logical
matrix J=J>1;
end
OUTPUT:
REGION GROWING
RESULT:
Thus the given input image executed and get region growing image successfully using
MATLAB Software.
EX.NO: 12 SEGMENTATION USING WATERSHED TRANSFORMATION
DATE:
AIM:
To perform watershed transform on an image
ALGORITHM:
1. Load the given image
Apply watershed transform
Display the resultant
images
PROGRAM:
clc;
x=checkerboard
(32);
subplot(2,2,1);
imshow(x);
title('given
image');
y=watershed(x,
4);
subplot(2,2,2);
imshow(y);
title('segmented image');
x1=imnoise(x,'salt&
pepper',0.1);
subplot(2,2,3),imshow(x1);
title('image added with
noise'); y1=watershed(x1,4);
subplot(2,2,4),imshow(y1);
title('segmented noisy-
image')
OUTPUT:
RESULT:
Watershed transform has been applied and studied on the given image
EX.NO: 13 ANALYSIS OF IMAGES WITH DIFFERENT COLOR MODELS
DATE:
AIM:
To analyze an image with different color models using MATLAB. Tasks to be performed
1) Conversion of an image to different color space
2) Detection of a color in RGB space.
REQUIREMENTS:
PC with MATLAB software.
ALGORITHM:
COLOR CONVERSION
1) Read the image from file location
2) Cast to double and display pixel information
3) Perform various color conversions in the image
4) Display the result
COLOR DETECTION
1) Read the image from file location
2) Split the original image into color bands
3) Set the threshold level for each color band and create a mask for the original image
4) Check whether are the masks combined become true
5) Obtain the red masked image with the specified threshold level
6) Display the result
PROGRAM:
% COLOR SPACE CONVERSION
clc;
clear all;
close all;
i1=imread('C:\Users\VM5606\Desktop\light1.jpg');
i1 = double(i1)/255; % Cast to double in the range [0,1]
subplot(3,3,1);
imshow(i1) % display
imtool(i1); % shows pixel information
title('Original image');
sz=size(i1);
i3 = rgb2gray(i1);
subplot(3,3,2);
imshow(i3);
title('RGB -> Gray');
i4 = rgb2ntsc(i1);
subplot(3,3,3);
imshow(i4);
title('RGB -> NTSC');
[X,map] = rgb2ind(i1,128);
subplot(3,3,4);
image(X);
colormap(map);
title('RGB -> Index');
axis off
axis image
i5 = ind2gray(X,map);
subplot(3,3,5);
imshow(i5);
title('Index -> Gray');
i6= ntsc2rgb(i4);
subplot(3,3,6);
imshow(i6);
title('NTSC -> RGB');
% Maximize figure.
set(gcf, 'Position', get(0, 'ScreenSize'));
% Display them.
subplot(3, 4, 2);
imshow(redBand);
title('Red band');
subplot(3, 4, 3);
imshow(greenBand);
title('Green band');
subplot(3, 4, 4);
imshow(blueBand);
title('Blue Band');
% Display them.
subplot(3, 4, 6);
imshow(redMask, []);
title('Red Mask');
subplot(3, 4, 7);
imshow(greenMask, []);
title('Green Mask');
subplot(3, 4, 8);
imshow(blueMask, []);
title('Blue Mask');
OUTPUT:
COLOR CONVERSION
PIXEL INFORMATION
COLOR DETECTION
RESULT:
` Thus analysis of images by color space conversion and color detection has been
performed using MATLAB.
EX.NO: 14 STUDY OF DICOMM STANDARDS
DATE:
AIM:
To study about DICOMM standards.
DESCRIPTION:
DICOM standards build as much as possible upon other standards. For example, DICOM
does not prescribe an image compression standard. Images stored as DICOM images can contain
the actual image data. A typical example of this is a JPEG image. DICOM 91 and 110 standardize
how metadata for an image, such as patient and visit data, acquisition modes and camera settings,
compression settings and data formats, and clinical interpretation, is stored as an integral part of the
image.
RESULT:
Thus DICOMM standard was studied.
EX.NO: 15 IMAGE COMPRESSION TECHNIQUES
DATE:
AIM
To implement an image Compression program using MATLAB.
ALGORITHM
clearall;
closeall;
input_image1=imread('heart.jpg');
input_image=imnoise(input_image1,'speckle',.01);
figure;
imshow(input_image);
n=input('enter the decomposition level=');
[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar');
[c,s] =
wavedec2(input_image,n,Lo_D,Hi_D);
disp('the decomposition vector output is');
disp(c);
[thr,nkeep] = wdcbm2(c,s,1.5,3*prod(s(1,:)));
[Compressed_image,TREE,Comp_ratio,PERFL2]=wpdencmp(thr,'s',n,'haar','threshold',5,1);
disp('Compression ratio in %');
disp(Comp_ratio);
re_ima1 =
waverec2(c,s,'haar'); re_ima =
uint8(re_ima1); subplot(1,3,1);
imshow(input_image);
title('I/P image');
subplot(1,3,2);
imshow(Compressed_image);
title('Compressed_image');
subplot(1,3,3);
imshow(re_ima);
title('reconstructed image');
OUTPUT
COMPRESSED IMAGE
RESULT:
Thus the given input image executed and get compressed image successfully using MATLAB
Software.
EX.NO: 16 IMAGE RESTORATION
DATE:
AIM
To implement an image restoration program using MATLAB.
ALGORITHM
PROGRAM
l=im2double(imread('heart.jpg'));
LEN=60;
THETA=0;
noise_var=0.001;
est_nsr=noise_var/var(l(:));
PSF=fspecial('motion',LEN,THE
TA);
wnr=deconvwnr(l,PSF,est_nsr);
imshow(wnr);
OUTPUT:
ORIGINAL IMGAE:
RESULT:
Thus the given input image executed and get restoration image successfully using MATLAB
Software.