Removal of noises at edges

조회 수: 3 (최근 30일)
Hg
Hg 2016년 1월 9일
댓글: Image Analyst 2016년 1월 9일
I have a grayscale (value 0-255) image with background pixel equals 0. I am trying to remove noises at the border between the foreground and the background. These noises can be identified by the big jump in values. Is there any existing algorithm/filter that can achieve this? If no, may I know the most efficient way to do it instead of comparing pixels with its neighborhood?
The result that I expect is to removal of those noises by changing them to background pixel (0) without changing any of the border/foreground pixel values.

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 9일
bigjump = diff(YourArray(:,1:end-1),1,1) > 32 | diff(YourArray(1:end-1,:),1,2) > 32);
bigjump(end+1,end+1) = false;
diff shortens the array in one direction but not the other, so to make arrays that are compatible to be or'd together, I take one fewer row or column in the other direction. Then the line after that is to pad out the matrix to the original size.
Now if you want to create mask from the first occurrence onward, you need to a cumulative "or". That can be done by cumsum() the logical value and comparing the result to 1 -- at least 1 true value at or before a location will result in 1 or more at that location.
jumped = cumsum(bigjump, 1) >= 1 | cumsum(bigjump, 2) >= 1;
and then
NewArray = YourArray;
NewArray(jumped) = 0;
  댓글 수: 1
Hg
Hg 2016년 1월 9일
Exactly what I needed. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 1월 9일
An alternative way is to use mathematical morphology. You can get the local min in a 3x3 (or whatever size or shape you want) using imerode()
localMin = imerode(grayImage, true(3));
% Find jumps by subtracting from the original
jumpThreshold = 32; % or whatever you want.
jumps = (grayImage - localMin) > jumpThreshold ; % This is a mask!
% Set big jump pixels to zero.
grayImage(jumps) = 0;
You could boil all that down to 2 lines of code (or even 1) if you wanted it to be super compact.
  댓글 수: 6
Hg
Hg 2016년 1월 9일
편집: Hg 2016년 1월 9일
I can't do that as some parts of the foreground have values close to or larger than 200. So the way I define noises is through the big jump in values.
Image Analyst
Image Analyst 2016년 1월 9일
A slight variant of what I code I gave is to use imopen(). It does an imerode() (local min) followed by imdilate() (local max). Try that also and see how it looks. Try varying the kernel size.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by