Biomedical Image Processing

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

BIOMEDICAL IMAGE PROCESSING

ASSIGNMENT: III
Name: ARUNA DEVI P

Roll Number: 20BBM004

1)

CODE :

I = imread('coins.png');
imshow(I)
BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
tiledlayout(1,2)
nexttile
imshow(BW1)
title('Sobel Filter')
nexttile
imshow(BW2)
title('Canny Filter')

I = imread('coins.png');
subplot(2,2,1)
imshow(I)
title('original image')
BW1=edge(I,'prewitt');
subplot(2,2,2);
imshow(BW1);
title('Prewitt');
se90 = strel('line', 6, 90);
se0 = strel('line', 6, 0);
BW2dil = imdilate(BW1, [se90 se0]);
subplot(2,2,3);
imshow(BW2dil);
title('Dilation');
BW3fill = imfill(BW2dil, 'holes');
subplot(2,2,4);
imshow(BW3fill);
title('Impact zone');
2)

CODE :

I = im2double(imread('rose.jpg'));
figure, imshow(I)
%imtool(I);
Isizes = size(I); %size of the image
threshI = multithresh(I, 3); %thresholding for three regions
[m, n]=ginput(1); %pick one pixel of the region to be segmented
c = impixel(I, m, n); %value of the pixel picked
currPix = c(1); %current pixel
surr = [-1 0; 1 0; 0 -1; 0 1]; %create a mask which represents the four
surrounding pixels
mem = zeros(Isizes(1)*Isizes(2), 3); %create a register to put the pixel
coordinates and pixel value
mem(1, :) = [m, n, currPix]; %insert initial picked pixel to the register
regSize = 1; %initial size
J = zeros(Isizes(1), Isizes(2)); %create another black image with the same size as
the original image
init = 1;
posInList = 1;
k=1; %create the initial condition to run the loop
%The region growing algorithm.
while(k==1)

for l=init:posInList %first pointer on the register


for j=1:4 %second pointer for the neighboring pixels
m1 = m + surr(j,1);
n1 = n + surr(j,2);

check=(m1>=1)&&(n1>=1)&&(m1<=Isizes(1))&&(n1<=Isizes(2)); %simple check if


pixel position still inside the image

current = impixel(I, m1, n1);


currPix = current(1);
if(check && currPix<=threshI(2) && (J(m1, n1)==0)) %check if it belongs to
the thresholding boundary and if not set yet on the image we want to recreate
posInList = posInList+1;
mem(posInList, :) = [m1, n1, currPix]; %add the new pixel
J(m1, n1) = 1;
end
end
end
if(posInList == init) %when there is no more pixels to add
k = 0; %make k=0 to close the loop
else
init = init+1;
m = mem(init, 1, :);
n = mem(init, 2, :);
k = 1; %keep running the loop
end
end
imshow(J); %the segmented black and white region
3)

CODE:

i1= imread("pepper.jfif");
subplot(2,2,1); imshow(i1);
I=rgb2gray(i1);
title( "Original Image"); % Specify initial contour location
mask= zeros(size(I));
mask (25:end-25, 25: end-25)= 1;
subplot(2,2,2);
imshow(mask); 
title('Initial Contour Location');
%Segment the image using the default method and 300 iterations
bw =activecontour (I, mask, 300); %Display segmented image
subplot(2,2,3);
imshow(bw);
title( 'Segmented Image');

%global thresholding
clc;
clear all; 
close all;
I = imread('pepper.jfif'); % read image
T = graythresh(I)
S=im2bw(I,T);
% find the threshold for Input IMAGE
subplot(1,2,1), imshow(I), title('Original Image');
subplot (1,2,2), imshow(S), title('Thresholded Image');
%adaptive thresholding
I1=imread('pepper.jfif');
subplot (2,1,1); 
imshow(I1); 
title("Original Image");
I=rgb2gray(I1);
%Compute adaptive threshold and display the local threshold
%This represents an estimate of average background illumination
T=adaptthresh(I,0.4, 'ForegroundPolarity', 'dark');
s=imbinarize(T);
%Binarize image using locally adaptive threshold
subplot(2,1,2);
imshow(s); title("Adaptive thresholded image");

4)
CODE :

% Image Registration
clc;
close all;
I=imread('2.jpg');
I1=imread('3.jpeg');
imshowpair(I,I1,"Scaling","joint")
[optimizer,metric] = imregconfig("multimodal")
movingRegistered = imregister(I,I1,"affine",optimizer,metric)
imshowpair(I,movingRegistered,"Scaling","joint")
5)

% Image Compression

clc;
close all;
a = imread("R.jpg");
ag = im2gray(a);
subplot(1,3,1)
imshow(a)
title('Original Image')
z = zeros(size(ag));
[x y] = size(ag);
for i = 1:x
    z(i,1) = ag(i,1);
    for j = 2:y
        z(i,j) = ag(i,j-1) - ag(i,j);
    end
end
subplot(1,3,3)
imshow(z)
title('Compressed Image')
subplot(1,3,2)
imshow(ag)
title('Gray Image')
% Mean square Error
I=imread('a.jpg');
A = imnoise(I,'salt & pepper', 0.02);
err = immse(A, I);
fprintf('\n The mean-squared error is %0.4f\n', err);
% Peak SNR and SNR
[peaksnr, snr] = psnr(A,I);
fprintf('\n The Peak-SNR value is %0.4f', peaksnr);
fprintf('\n The SNR value is %0.4f \n', snr);

% Image Compression

clc;
close all;
a = imread("R.jpg");
ag = im2gray(a);
subplot(1,3,1)
imshow(a)
title('Original Image')
z = zeros(size(ag));
[x y] = size(ag);
for i = 1:x
    z(i,1) = ag(i,1);
    for j = 2:y
        z(i,j) = ag(i,j-1) - ag(i,j);
    end
end
subplot(1,3,3)
imshow(z)
title('Compressed Image')
subplot(1,3,2)
imshow(ag)
title('Gray Image')
% Mean square Error
I=imread('a.jpg');
A = imnoise(I,'salt & pepper', 0.02);
err = immse(A, I);
fprintf('\n The mean-squared error is %0.4f\n', err);
% Peak SNR and SNR
[peaksnr, snr] = psnr(A,I);
fprintf('\n The Peak-SNR value is %0.4f', peaksnr);
fprintf('\n The SNR value is %0.4f \n', snr);
6)

clc;
clear all;
close all;
message=input('Enter the text message sequence: ');
source=unique(message)
counts=zeros(1,length(source));
for i=1:length(source)
counts(i)=length(strfind(message,source(i)));
end
counts
seq=zeros(1,length(message));
for i=1:length(message)
seq(i)=strfind(source,message(i));
end
seq
code = arithenco(seq, counts)
dseq=arithdeco(code,counts,length(seq))
dec_mess=zeros(1,length(dseq));
for i=1:length(dseq)
a=dseq(i);
dec_mess(i)=source(a);
end
char(dec_mess)

You might also like