MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by ARUN SAI
on 24 May 2013

This is the code written for color filtering method for CFA images based on Gradient. According to this project during image acquisition through single sensor digital camera, there may be some noise created during demosaicking process and also artifacts.which iam trying to remove it by gradient. After running the program, iam getting the simulation result as that there is no noise in the image according to the code.*so suggest me if any correction in the code ie, after the comment regarding TH enumeration variable *

for i=2:1:m-1

for j=2:1:n-1

A1=abs(r(i-1,j-1)-r(i+1,j+1)); % horizontal internal gradient

B1=abs(r(i-1,j+1)-r(i+1,j-1)); % vertical internal gradient

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)); % horizontal external gradient

B2=abs(2*g(i,j)-g(i-2,j-1)-g(i+2,j+1)); % vertical external gradient

end end

% to find existence of edge or influence of the noise TH (enumeration variable) is used for noise that in the up and down or in any point of g(i,j)

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]

**is it right way to find the existence of noise and edges in a color image ie, horizantal and vertical gradient in horizantal and vertical direction**

*No products are associated with this question.*

## 5 Comments

## Image Analyst (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76838#comment_150669

http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

## Image Analyst (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76838#comment_150674

What is "the o/p as"??? And do you have a question? If you do, please make it

super-explicit and crystal clear, preferably with data, screenshots, or anything else that you think may help us help you.## ARUN SAI (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76838#comment_150819

what i mean by saying o/p(output) is after running the program.

## Image Analyst (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76838#comment_150965

No image posted yet, and not crystal clear yet.

## ARUN SAI (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76838#comment_151048

image i am using

mandi.tifwhich is raw image in matlab library