Showing posts with label Image Processing Practicals. Show all posts
Showing posts with label Image Processing Practicals. Show all posts

Thursday, 29 December 2016


Image Preprocessing Techniques 


  • Roberts Filter
  • Prewitt Filter
  • Sobel Filter
  • Laplacian Filter 
  • Median Filter












Submitted by-  Miss. Shruti Naik

Prof.Mahendra Kanojia


Discrete Cosine Transform and Inverse Discrete Cosine Transform




Submitted by - Shruti Naik


Prof.Mahendra Kanojia

HUFFMAN Coding 



Submitted by - Shruti Naik

Prof.Mahendra Kanojia

High Boost Filtering




Submitted by - Shruti Naik

Prof.Mahendra Kanojia

Sunday, 10 April 2016


clc; clear all; close all;

function out_put = btc_image(in_put,block_size)
X=imread('rice.png');
Y=imfinfo('rice.png');
K=input('Enter the block size');
X1=double(X);
y1=size(X);
n=y1(1);
m=y1(2);
k=1;l=1;

if (Y.ColorType=='grayscale')

% IMAGE ENCODING
% FOR GRAY SCALE IMAGES

subplot(131),imshow(X),title('ORIGINAL');
disp('K=');
disp(K);
for i=1:K:n
    for j=1:K:m
        tmp([1:K],[1:K])=X1([i:i+(K-1)],[j:j+(K-1)]);
        mn=mean(mean(tmp));
        tmp1([i:i+(K-1)],[j:j+(K-1)])=tmp>mn;
        Lsmat=(tmp<mn);
        Mrmat=(tmp>=mn);
        Lsmn=sum(sum(Lsmat));
        Mrmn=sum(sum(Mrmat));
        Mu(k)=sum(sum(Lsmat.*tmp))/(Lsmn+.5);k=k+1;
        Mi(l)=sum(sum(Mrmat.*tmp))/Mrmn;l=l+1;
    end
end

subplot(132),imshow(tmp1);title('ENCODED');




% IMAGE DECODING

k=1;l=1;
for i=1:K:n

    for j=1:K:m
        tmp21([1:K],[1:K])=tmp1([i:i+(K-1)],[j:j+(K-1)]);
        tmp22=(tmp21*round(Mu(k)));k=k+1;
        tmp21=((tmp21==0)*round(Mi(l)));l=l+1;
        tmp21=tmp21+tmp22;
        out_put([i:i+(K-1)],[j:j+(K-1)])=tmp21;
    end
end
subplot(133),imshow(uint8(out_put));title('DECODED');

% FOR COLORED IMAGES

elseif (Y.ColorType=='truecolor')
    R=X(:,:,1);
    G=X(:,:,2);
    B=X(:,:,3);

    % IMAGE ENCODING

subplot(131),imshow(X),title('ORIGINAL');
for b=1:3
    for i=1:K:n
            for j=1:K:m
                tmp([1:K],[1:K])=X1([i:i+(K-1)],[j:j+(K-1)],b);
                mn=mean(mean(tmp));
                tmp1([i:i+(K-1)],[j:j+(K-1)],b)=tmp>mn;
                Lsmat=(tmp<mn);
                Mrmat=(tmp>=mn);
                Lsmn=sum(sum(Lsmat));
                Mrmn=sum(sum(Mrmat));
                Mu(b,k)=sum(sum(Lsmat.*tmp))/(Lsmn+.5);k=k+1;
                Mi(b,l)=sum(sum(Mrmat.*tmp))/Mrmn;l=l+1;
            end
    end
end
subplot(132),imshow(tmp1);title('ENCODED');

% IMAGE DECODING

k=1;l=1;
for b=1:3
    for i=1:K:n
            for j=1:K:m


             tmp21([1:K],[1:K])=tmp1([i:i+(K-1)],[j:j+(K-1)]);
             tmp22=(tmp21*round(Mu(b,k)));k=k+1;
             tmp21=((tmp21==0)*round(Mi(b,l)));l=l+1;
             tmp21=tmp21+tmp22;
                out_put([i:i+(K-1)],[j:j+(K-1)],b)=tmp21;
          end
    end
end
subplot(133),

imshow(uint8(out_put));
title('DECODED');
else
     errordlg('IMAGE TYPE NOT SUPPORTED');
   

end

Prof.Mahendra Kanojia

% **** HISTOGRAM STRETCHING ****

a=imread('old imagelc.jpg');
aa=double(a);
[row col]=size(aa);
h=zeros(1,300);
rmax=(max(max(aa)));
rmin=(min(min(aa)));
slope=255/(rmax-rmin);
smin=0;
aa=aa+1;
for x=1:row
    for y=1:col
        c(x,y)=slope*(aa(x,y)-rmin)+smin;
    end
end
for x=1:row
    for y=1:col
   %if aa(x,y)==0
    %   aa(x,y)=1;
        t=aa(x,y);
        h(t)=h(t)+1;
    end
end
figure(1);
bar(h);
z=zeros(1,300);
for x=1:row
    for y=1:col
        %if aa(x,y)==0
         %   aa(x,y)=1;
        p=round(c(x,y));
        z(p)=z(p)+1;
    end
end
end
figure(2);
bar(z);
figure(3);
imshow(uint8(c));
figure(4);

imshow(uint8(aa));




Prof.Mahendra Kanojia


% **** HOMOMORPHIC FILTERING ****

a=imread('Ranch house.jpg');
r1=double(a);
[row col]=size(r1);
b=r1;
D0=input('enter cut off : ');
Yh=input('enter the value of Yh :');
Yl=input('enter the value of Yl :');
C=input('enter the value of c :');
for x=1:1:row
    for y=1:1:col
        if r1(x,y)==0
            b(x,y)=1;
        end
    end
end
for u=1:1:row
      for v= 1:1:col
   D=((u-row/2)^2+(v-col/2)^2)^0.5;
       H(u,v)=(Yh-Yl)*(1-exp(-C*(D*D/D0*D0)))+Yl;
      
  end
end
m=log(b);
x=fft2(m);
v=fftshift(x);
v1=v.*H;
g1=(abs(ifft2(v1)));
g=exp(g1);
figure(1);
imshow(uint8(g));
figure(2);

imshow(uint8(r1));

Prof.Mahendra Kanojia

% region filling
clc;
close all;
clear all;
% Input
A=[0 0 0 0 0 0 0
   0 0 1 1 0 0 0
   0 1 0 0 1 0 0
   0 1 0 0 1 0 0
   0 0 1 0 1 0 0
   0 0 1 0 1 0 0
   0 1 0 0 0 1 0
   0 1 0 0 0 1 0
   0 1 1 1 1 0 0
   0 0 0 0 0 0 0];

figure(1),clf,colormap('gray')    % CLF-> Clear current figure
subplot(1,3,1),imagesc(A);        % IMAGESC-> Scale data and display as image.

Ac = ones(size(A)) - A;           % Ac --> A's complement

B = [0 1 0; 1 1 1; 0 1 0];        % Restructuring Element

x = zeros(size(A));
x(3,3)=1;   % Start Point

k=0;
flag_region_found = 0;

while flag_region_found ~= 1,
   k = k+1;
   subplot(1,3,2),imagesc(x);
  
   %drawnow-> Flush pending graphics events.

     xnew = and(dilate(x,B),Ac); 
    % DILATE --> Perform dilation on binary image.     
   x
   xnew


   xnew-x
   sum(xnew-x)
   sum(sum(xnew-x))
  
   if sum(sum(xnew-x))== 0,
       flag_region_found = 1;
   else
      x=xnew;
      % disp(['iteration # ' int2str(k)]);
   end
   pause(.6)
end

y = x+A;

subplot(1,3,3),imagesc(y);

Output:-

On Command Window:-


x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0




ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     1     0     0     0
     0     0     1     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     1     1     0     0     0

ans =

     2

x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0

xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     1     0     0     0

ans =

     1

x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     1     0     0     0

ans =

     1

x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     1     0     0     0

ans =

     1

x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     1     0     0     0

ans =

     1
 
x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     1     1     1     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     0     1     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     1     1     1     0     0

ans =

     3

x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     1     1     1     0     0
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     1     1     1     0     0
     0     0     1     1     1     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     0     1     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     1     0     1     0     0

ans =

     2

x =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     1     1     1     0     0
     0     0     1     1     1     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


xnew =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     1     0     0     0
     0     0     1     1     0     0     0
     0     0     0     1     0     0     0
     0     0     0     1     0     0     0
     0     0     1     1     1     0     0
     0     0     1     1     1     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0


ans =

     0     0     0     0     0     0     0


ans =


     0


Prof.Mahendra Kanojia