clc
clear all;
close all;
i1=imread('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh03b135aTFlCJmQBdKvqcaZ120p1ou2gbp-dD52dyyQbXkf6eX6Bu8m__XH4Vn9JiczEBRREanLjGcCIHQ3uGZ9bFT7N-8kENOfM3Jg36RiPZvYkADhfdD8xDsG7I8IKyxQ-E9zSY1O-j/s1600/mri-brain.jpg');
[r,c]=size(i1);
l=input('No. of intensity levels required : (in multiples of two) ');
x=256/l;
y=floor(255/(l-1));
im1=i1;
temp=1;
for i =1:r
for j=1:c
if i1(i,j)<=(x-1)
im1(i,j)=0;
end
end
end
for temp =1:(l-1)
for i=1:r
for j=1:c
if (i1(i,j)>=(temp*x)) & (i1(i,j)<=((((temp*x)+x)-1)))
im1(i,j)=temp*y;
end
end
end
end
figure,subplot(2,1,1),imshow(i1);subplot(2,1,2),imshow(im1);
clear all;
close all;
i1=imread('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh03b135aTFlCJmQBdKvqcaZ120p1ou2gbp-dD52dyyQbXkf6eX6Bu8m__XH4Vn9JiczEBRREanLjGcCIHQ3uGZ9bFT7N-8kENOfM3Jg36RiPZvYkADhfdD8xDsG7I8IKyxQ-E9zSY1O-j/s1600/mri-brain.jpg');
[r,c]=size(i1);
(Sample Image) |
l=input('No. of intensity levels required : (in multiples of two) ');
x=256/l;
y=floor(255/(l-1));
im1=i1;
temp=1;
for i =1:r
for j=1:c
if i1(i,j)<=(x-1)
im1(i,j)=0;
end
end
end
for temp =1:(l-1)
for i=1:r
for j=1:c
if (i1(i,j)>=(temp*x)) & (i1(i,j)<=((((temp*x)+x)-1)))
im1(i,j)=temp*y;
end
end
end
end
figure,subplot(2,1,1),imshow(i1);subplot(2,1,2),imshow(im1);