Wednesday, 20 January 2016

Reducing the Number of Intensity Levels in an Image

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);
(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);

Tuesday, 19 January 2016

Zoom_Image_Method2_(_by Pixel Replication)

clc;
clear all;
close all;

im1=imread('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWSg9XpAfMMTDbbGSVal1fG65pAQbQDz0TM9m634fgKb3AkUmaV8GPt1rTrQ7_lUyUZ6gh3VmidsERX-C-x2qQ8HFYX9jSToF2plpVVRI3W6cI6j2T05Q8CpqEWZk9lSUz3T3B94eZCfo/s1600/apknee1+copy.jpg');
(Image to be zoomed)

% a=randint(3,3,10);
% [r,c]=size(a);

[r,c]=size(im1);
n=input('How many times should the image be zoomed? ');

i=1:n;
j=1:n;
t=(n-1);

for num=1:r
    b(i,j)=im1(num);
    i=i+n:i+n+t;   
end

for x=1:(r-1)
 i=1:n;j=(1+(n*x)):(n*(x+1));
for num=num+1:num+r
    b(i,j)=im1(num);
    i=i+n:i+n+t;   
end
end

subplot(2,1,1),imshow(im1);
subplot(2,1,2),imshow(b);

Zoom_Image_Method1 (_by Pixel Replication)

clc
clear all
close all;

n=input('How many times should the image be zoomed? ');

a=randint(3,3,10);
[r,c]=size(a);

i=1;
for num=1:c
    b(:,i)=a(:,num);
        for t=1:n
            b(:,i+t-1)=b(:,i);
        end
    i=i+n;
end

[r,c]=size(b);
i=1;

for num=1:r
    d(i,:)=b(num,:);
    for t=1:n
        d(i+t-1,:)=d(i,:);
    end
    i=i+n;
end

figure,imshow(a);
figure,imshow(d);