where is my code gone wrong,suggest me if any correction.it is always showing case 5 ie, no noise even though noise is applied .is the code is right?

1 次查看(过去 30 天)
clc; clear all; close all; i = imread('mandi.tif'); %demosaic of image rgb = demosaic(i,'bggr'); figure,e=imshow(rgb); m1=mean2(rgb); SD1=mean2(stdfilt(rgb)); snr1=(m1/SD1) h = imrect(gca, [1688 547 850 900]); f = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim')); setPositionConstraintFcn(h,f); % masking mask = createMask(h,e); for i=100:1:200 for j=100:1:200 rgb(i,j)=imnoise(rgb(i,j),'gaussian',0.01); end end figure,imshow(rgb); 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) for i=2:1:m-1 for j=2:1:n-1 A1=abs(g(i,j-1)-g(i,j+1)); B1=abs(g(i-1,j)-g(i+1,j)); end end for i=3:1:m-2 for j=3:1:n-2 A2=abs(2*b(i,j)-b(i,j-2)-b(i,j+2)); B2=abs(2*b(i,j)-b(i-2,j)-b(i+2,j)); 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*g(k,y)-g(k-1,l)-g(k+1,l))),l-1); down=(A1<B1)&(eq(A2,B2))&eq(max(abs(2*g(k,y)-g(k-1,l)-g(k+1,l))),l+1); left=(A1>B1)&(eq(A2,B2))&eq(max(abs(2*g(x,l)-g(k,l-1)-g(k,l+1))),k-1); right=(A1>B1)&(eq(A2,B2))& eq(max(abs(2*g(x,l)-g(k,l-1)-g(k,l+1))),k+1); no=(eq(A1,B1))&(eq(A2,B2)); level=(A1>B1)&(A2>B2); erect=(A1>B1)&(A2<B2); end end p=[1 2 3 4 5 6 7] TH=[up down left right no level erect] p_TH=p(TH==1) switch p_TH case 1 g(i,j)=(g(i-1,j)+g(i+1,j)+g(i,j+1))/3; g(i,j-1)=g(i,j); case 2 g(i,j)=(g(i-1,j)+g(i+1,j)+g(i,j-1))/3; g(i,j+1)=g(i,j); case 3 g(i,j)=(g(i+1,j)+g(i,j-1)+g(i,j+1))/3; g(i-1,j)=g(i,j); case 4 g(i,j)=(g(i-1,j)+g(i,j-1)+g(i,j+1))/3; g(i+1,j)=g(i,j); case 5 g(i,j)=(g(i-1,j)+g(i+1,j)+g(i,j-1)+g(i,j+1))/4; case 6 g(i,j)=(g(i-1,j)+g(i+1,j))/2; case 7 g(i,j)=(g(i,j-1)+g(i,j+1))/2; end s=r+g+b; figure,imshow(s); m2=mean2(s); SD2=mean2(stdfilt(s)); snr2=(m2/SD2)

回答(1 个)

Image Analyst
Image Analyst 2013-5-12
  3 个评论
Image Analyst
Image Analyst 2013-5-13
If it's your code, why do you need it explained to you? And why will you not use the debugger like 99% of all other MATLAB programmers?
ARUN SAI
ARUN SAI 2013-5-15
this code is written by me, but even though i applied noise it is showing that there is no noise and edge....so i need help regarding the code..,

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by