Showing posts with label Digital Image Processing. Show all posts
Showing posts with label Digital Image Processing. Show all posts
Sunday, 10 April 2016
clc;clear
all;close all;
%
=========================================
% Mean Filter
%
=========================================
f
= imread('saturn.tif');
subplot(2,2,1);
imshow(f);
title('Original
Image');
m
= mean2(double(f));
g
= imfilter(f,m);
k
= imabsdiff(f,g);
subplot(2,2,2);
imshow(g);
title('Mean
Filtered Image');
subplot(2,2,3);
imshow(k);
title('Absolute
Difference of f ang g');
%
=========================================
% Median filter
%
=========================================
figure;
f
= imread('saturn.tif');
g
= imnoise(f,'salt & pepper',0.06);
subplot(1,2,1);
imshow(g);
title('Input
Image');
%K
= filter2(fspecial('average',3),g)/255;
M
= medfilt2(g,[3 3]);
%figure,
imshow(K)
subplot(1,2,2);
imshow(M);
title('Median
filtered image');
%
=========================================
% Minimax filter
%
=========================================
figure;
f
= imread('saturn.tif');
subplot(1,2,1);
imshow(f);
title('Original
Image');
n
= 5; % Filter order
freq
= [0 0.4 0.5 1]; % Frequency band edges
a
= [1 1
0 0]; % Desired amplitudes
b
= remez(n,freq,a);
L
= imfilter(f,b);
subplot(1,2,2);
imshow(L);
clc;clear all;close all;
infile = 'car.jpg'; % 3D Image
if (exist(infile)==2)
a =
imread(infile);
subplot(1,2,1);
imshow(a);
title('Input image');
else
warndlg('The file does not exist.',' Warning ');
im=[];
return
end
singvals = 20;
%if isrgb(a)
if
isa(a(:,:,1),'uint8')
red = double(a(:,:,1));
green = double(a(:,:,2));
blue = double(a(:,:,3)); %
For 3D Image
% S = SVDS(A,K) computes the K largest
singular values of A.
[u,s,v] = svds(red, singvals);
imred = uint8(u * s * transpose(v));
[u,s,v] = svds(green, singvals);
imgreen = uint8(u * s * transpose(v));
[u,s,v] = svds(blue, singvals);
% For 3D Image
imblue = uint8(u * s * transpose(v));
% For 3D Image
im1(:,:,1) = imred;
im1(:,:,2) = imgreen;
im1(:,:,3) = imblue;
% For 3D Image
%imwrite(im, outfile);
%figure('Name','Output image');
Image1 = a;
Image2 = im1;
save('c:\Image1.jpg');
save('c:\Image2.jpg','im1');
subplot(1,2,2);
imshow(im1);
title('Compressed Image');
end
Note: Check the size of original and compressed image in C drive of your system
![]() |
| Lossless Image Compression |
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
% **** 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));
% **** 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));
clc;clear
all;close all;
load sumsin;
s = sumsin;
figure
('Name','Input 1-D Signusoidal Signal');
plot(s);
figure
('Name','Decomposition');
[c,l] =
wavedec(s,4,'bior1.1');
subplot(2,2,1);
plot(c);
title('Function
at resolution level 4');
[c,l] =
wavedec(s,8,'bior1.1');
subplot(2,2,2);
plot(c);
title('Function
at resolution level 8');
[c,l] =
wavedec(s,16,'bior1.1');
subplot(2,2,3);
plot(c);
title('Function
at resolution level 16');
[c,l] =
wavedec(s,32,'bior1.1');
subplot(2,2,4);
plot(c);
% 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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