Info

This question is closed. Reopen it to edit or answer.

sir i have the code for my project color filtering method for CFA image based on gradient but iam not getting exact result, so please explain me the code has gone wrong.

1 view (last 30 days)
sir please explain me that where the code has gone wrong,instead of applying noise to the image the result is showing that there is no noise and even it showing that there is no edges in the image.
clc;
clear all;
close all;
i = imread('mandi.tif');
imshow(i);
%demosaic of image
rgb = demosaic(i,'bggr');
figure,imshow(rgb);
%noise addition
for i=500:1:1000
for j=500:1:1000
rgb(i,j)=imnoise(rgb(i,j),'gaussian',9);
end
end
figure,imshow(rgb);
%SNR calculation of image with noise
m1=mean2(rgb);
SD1=mean2(stdfilt(rgb));
snr1=(m1/SD1)
r=rgb;g=rgb;b=rgb;
r(:,:,2)=0;
r(:,:,3)=0;
g(:,:,1)=0;
g(:,:,3)=0;
b(:,:,1)=0;
b(:,:,2)=0;
m = size(rgb,1)
n = size(rgb,2)
%determination of enumeration variable TH for knowing the existence of noise and edges in a color image
for i=2:1:m-1
for j=2:1:n-1
A1=abs(r(i-1,j-1)-r(i+1,j+1));
B1=abs(r(i-1,j+1)-r(i+1,j-1));
end
end
for i=3:1:m-2
for j=3:1:n-2
A2=abs(2*g(i,j)-g(i-1,j-2)-g(i+1,j+2));
B2=abs(2*g(i,j)-g(i-2,j-1)-g(i+2,j+1));
end
end
for k=2:2:m-1
for l=3:2:n-1
x=[k-1,k+1];
y=[l-1,l+1];
up=(A1<B1) & (eq(A2,B2)) & eq(max(abs(2*r(k,y)-r(k-1,l)-r(k+1,l))),l-1);
*%up says that g(i,j-1) is the noise*
down=(A1<B1) & (eq(A2,B2)) & eq(max(abs(2*r(k,y)-r(k-1,l)-r(k+1,l))),l+1); *%down says that g(i,j+1) is the noise*
left=(A1>B1) & (eq(A2,B2)) & eq(max(abs(2*r(x,l)-r(k,l-1)-r(k,l+1))),k-1); *%left says that g(i-1,j) is the noise*
right=(A1>B1) & (eq(A2,B2)) & eq(max(abs(2*r(x,l)-r(k,l-1)-r(k,l+1))),k+1); *%right says that g(i+1,j) is the noise*
no=(eq(A1,B1)) & (eq(A2,B2));
*%no says that there is no noise and also no edge *
level=(A1>B1) & (A2>B2);
*%level says that there is a edge in vertical direction*
erect=(A1>B1) & (A2<B2);
*%erect says that there is a edge in horizontal direction*
end
end
p=[1 2 3 4 5 6 7]
TH=[up down left right no level erect]
p_TH=p(TH==1)
for i=2:1:m-1
for j=2:1:n-1
switch p_TH
case 1
r(i,j)=(r(i-1,j)+r(i+1,j)+r(i,j+1))/3;
r(i,j-1)=r(i,j);
case 2
r(i,j)=(r(i-1,j)+r(i+1,j)+r(i,j-1))/3;
r(i,j+1)=r(i,j);
case 3
r(i,j)=(r(i+1,j)+r(i,j-1)+r(i,j+1))/3;
r(i-1,j)=r(i,j);
case 4
r(i,j)=(r(i-1,j)+r(i,j-1)+r(i,j+1))/3;
r(i+1,j)=r(i,j);
case 5
r(i,j)=(r(i-1,j)+r(i+1,j)+r(i,j-1)+r(i,j+1))/4;
case 6
r(i,j)=(r(i-1,j)+r(i+1,j))/2;
case 7
r(i,j)=(r(i,j-1)+r(i,j+1))/2;
end
end
end
s=r+g+b;
figure,imshow(s);
%SNR calculation of image after processing
m2=mean2(s);
SD2=mean2(stdfilt(s));
snr2=(m2/SD2)

Answers (1)

Image Analyst
Image Analyst on 27 May 2013
I already gave some things to try when you posted this same question under your alternate identity: http://www.mathworks.com/matlabcentral/answers/76726-can-any-one-suggest-any-corrections-or-changes-for-the-code-witten-by-me. Things like giving indexes to A1, etc. Why have you not tried any of my suggestions?
  1 Comment
KAS
KAS on 28 May 2013
sorry but it cannot make any changes in my result. whether the noise applied is not enough to be identified as a noise in the code.what should i do.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!