MATLAB Answers

Karl
0

Filter evenly spaced vertical and horizontal lines

Asked by Karl
on 8 Jul 2011
I'm doing some temperature downscaling that results in vertical and horizontal artifacts or "lines" in my output image. I would like to remove the artifacts using some form of filtering while changing the rest of the data as little as possible.
Example MATLAB workspace with matrix as variable "A" is here: http://fiesta.bren.ucsb.edu/~krittger/misc/filter_question/filt_question_data.mat
I've tried a few things using fspecial and imfilter but the high gradient in the other parts of the image get changed too.

  0 Comments

Sign in to comment.

1 Answer

Answer by Sean de Wolski
on 8 Jul 2011

%A is your variable
Mx = false(size(A)); %masks in each dimension
My = Mx;
[fx fy] = gradient(A);
idx_x = find(abs(sum(fx))>50); %find lines
idx_y = find(abs(sum(fy,2))>35);
My(idx_y,:) = true; %turn lines on in mask
Mx(:,idx_x) = true;
K = fspecial('gaussian',7,.5);
Ablur = imfilter(A,K);
A2 = A;
M = Mx|My;
A2(M) = Ablur(M); %overwrite masked parts
The trick is to set up a map of the lines. I did that here (two separate maps in case you want to filter dimensions separately). Then once you have the mask, only replace the parts of the image in the mask with the blurred part. The above is just an example - it obviously needs tuning. You may also want to morphologically dilate ( imdilate ) to make sure it covers the lines.
Good luck!

  0 Comments

Sign in to comment.