0% found this document useful (0 votes)
34 views2 pages

Practical 3 Code

Practical 3 code
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Practical 3 Code

Practical 3 code
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

29/8/25 11:18 AM D:\B1 BIP\p3.

m 1 of 2

clc;
clear all;
close all;

im1=imread('D:\Biomedical Image Processing\sample images\DIP3E_Original_Images_CH03\5.


tif');
im2=imread('D:\Biomedical Image Processing\sample images\DIP3E_Original_Images_CH03\7.
tif');
im3=imread('D:\Biomedical Image Processing\sample images\DIP3E_Original_Images_CH03\8.
tif');
% ******** contrast stretching*******
i1=im2double(im1);
m1=min(min(i1));
m2=max(max(i1));
i2=(i1-m1)./(m2-m1);
i3 = im2uint8(i2);
figure,subplot(2,1,1); imshow(im1); title('Original Image');
subplot(2,1,2); imshow(i3); title('Contrast-Stretched Image');
% ********** gray level slicing*********
x = 0:255;
y1 = 10*ones(size(x));
y1(145:230) = 250;
y2 = x;
y2(145:230) = 250;
[m,n]=size(im2);
% 1) Intensity level slicing
t1=zeros(m,n);
for i=1:1:m
for j=1:1:n
if im2(i,j)>=145 && im2(i,j)<=230
t1(i,j)=200;
else
t1(i,j)=0;
end
end
end
figure,subplot(3,2,3), plot(x,y1); title('Binary Gray-level Slicing Transform');
axis([0 255 0 255]); xlabel('Input Gray Level, r');
ylabel('Output Gray Level, s');
subplot(3,2,4),plot(x,y2); title('Linear Gray-level Slicing Transform');
axis([0 255 0 255]); xlabel('Input Gray Level, r');
ylabel('Output Gray Level, s');
subplot(3,2,1), imshow(im2); title('Original Image');
subplot(3,2,5), imshow(t1); title('Binary Gray-level Sliced Image');
% 2) Intensity level slicing
t2=zeros(m,n);
for j=1:1:n
if im2(i,j)>=145 && im2(i,j)<=230
t2(i,j)=250;
else
t2(i,j)=im2(i,j);
29/8/25 11:18 AM D:\B1 BIP\p3.m 2 of 2

end
end
t3=uint8(t2);
subplot(3,2,6),imshow(t3);colormap(gray),title('intensity level slicing' );
% ******** bit-plane slicing********
img8 = double(bitand(im3,128));
img7 = double(bitand(im3,64));
img6 = double(bitand(im3,32));
img5 = double(bitand(im3,16));
img4 = double(bitand(im3,8));
img3 = double(bitand(im3,4));
img2 = double(bitand(im3,2));
img1 = double(bitand(img2,1));
figure,subplot(2,4,1); imshow(img8); title('Bit-plane 8');
subplot(2,4,2); imshow(img7); title('Bit-plane 7');
subplot(2,4,3); imshow(img6); title('Bit-plane 6');
subplot(2,4,4); imshow(img5); title('Bit-plane 5');
subplot(2,4,5); imshow(img4); title('Bit-plane 4');
subplot(2,4,6); imshow(img3); title('Bit-plane 3');
subplot(2,4,7); imshow(img2); title('Bit-plane 2');
subplot(2,4,8); imshow(img1); title('Bit-plane 1');
% image plane 8,7,6
ad1=img8+img7+img6;
figure,subplot(2,3,1),imshow(im3);title('original image');
subplot(2,3,2),imshow(uint8(ad1)),colormap('gray'),title('image plane 8,7,6');
% image plane 8,7,6,5
ad2=img8+img7+img6+img5;
subplot(2,3,3),imshow(uint8(ad2));colormap('gray');title('image plane 8,7,6,5');
% image plane 7,6,5,4,3
ad3=img8+img7+img6+img5+img4;
subplot(2,3,4),imshow(uint8(ad3));colormap('gray');title('image plane 8,7,6,5,4');

You might also like