move a 3*3 window on a binary image
이전 댓글 표시

hi I have a 3*3 window and a binary image..I want to move this window on this image... how can do this? thanks
댓글 수: 1
David Young
2014년 9월 3일
What operation do you want to carry out?
답변 (2개)
Image Analyst
2014년 9월 3일
0 개 추천
Try imfilter(), conv2(), or nlfilter(), or possibly blockproc(). That's about all I can say until you provide more information.
댓글 수: 17
Image Analyst
2014년 9월 3일
So, if in your 3 by 3 window, any of the values in the left most column match any of the values in the right-most column, regardless if they are in the same row or different rows, fill the entire 3by3 window in the output location with the value that matches? What if there are 2 matches, like the (1,1) pixel matches the (2,3) pixels with value 1(true) and the (2,1) pixels matches the (3,3) pixel with value 0? Is the 3x3 output square set to 0 or 1?
atefeh gh
2014년 9월 3일
Image Analyst
2014년 9월 3일
What's the overall intent anyway? What do you really want to do, such that you devised this unusual algorithm for? Maybe there's a way to get what you want without doing this unusual thing, which I think will probably be done best with nlfilter().
atefeh gh
2014년 9월 3일
Image Analyst
2014년 9월 3일
You can but you have to define the algorithm better. Are you sure they're not just doing a morphological closing ()a local max)? If it's more like what you say then you need to answer by first comment. Maybe you just need to know if there is a 1 in any row of the left column and another 1 in any row of the right column. And, do we need to set the whole 3x3 window in the output image to 1 (very unusual), or just the center pixel where the window is centered (which is nearly every case I've ever seen)? Perhaps you can just do it with two simple calls to imfilter() or conv2() with a clever kernel, followed by thresholding and ANDing.
atefeh gh
2014년 9월 3일
Image Analyst
2014년 9월 3일
You didn't attach anything, but I don't have much, or any, time for figuring out papers and explaining them to people, though people ask all the time. Sorry but I don't even have time for the papers I'd like to read, much less those that others are reading. Hope you understand. Maybe if it's a short paragraph explaining only that window-scanning part I might be able to figure out what they did, but no promises.
Joseph Cheng
2014년 9월 3일
편집: Joseph Cheng
2014년 9월 3일
It sounds like what is is being attempted is pass a low pass filter (if center value or all windowed pixel are replaced by its surroundings/edges) to get rid of small (based on the 3x3) "holes" or "peaks". If this is going to be a lung or rest of chest cavity binary image then wouldn't imfill() and/or imerode "fill"/"erode" these gaps in the image?
why not try a conv2() of ones(3,3)/9 (ie the average of the 3x3 window) and then putting a threshold based on what majority of ones vs zeroes would make it be replaced.
Image Analyst
2014년 9월 3일
No it's definitely not a low pass filter, that's a linear filter by the way. What he's asking for is a non-linear filter (median and dilation are some examples of non-linear filters). He wants to ignore the middle column and see if a pixel in the left column matches its partner on the right column (or maybe any pixel in the right column, that's what I'm asking him to tell us). So if you had two lines separated by a space (like edges of a bronchial tube), then it would fill in the space between the edges. It would not affect things outside the tube. Of course this is very dependent on window width and tube width. For example it would not work on edges separated by 3 or 4 columns of space. You'd have to use a bigger window for that and check more pixels. I'm wondering if the window size needs to be adjusted depending on the side of the tubes. Plus it would only work for vertical tubes, not horizontal ones.
I think there may be a way to construct this non-linear filter from two passes of a convolution with special kernels and thresholding but we need a better definition of how the left and right are compared to see how many kernels we'd need and what the threshold values need to be. But it wouldn't be a straight moving average (blurring).
Joseph Cheng
2014년 9월 3일
편집: Joseph Cheng
2014년 9월 4일
Ah i see, it has been a while and mixed the term with what i described with the averaging. Also i was thinking opposite edges included top and bottom of the 3x3 in the consideration of what the middle pixel will be. That is why i was thinking an averaging with a threshold on what constitutes how much of the window needed to be 1's or 0's
Image Analyst
2014년 9월 4일
You can filter with
1 0 0
1 0 0
1 0 0
with imfilter() to see if there are any "true" pixels on the left in your binary image. And you can filter with
0 0 1
0 0 1
0 0 1
in imfilter() to see if there are any in the right column. Then you can AND those output images together to see if there is at least one pixel in any row in the left column and in any row of the right column. Then you can OR that with your original binary image to fill in (set to 1) any pixel that has non-zero pixels in both the the left and right columns. You can't do it in a single convolution. If you need to match up row 1 with row 1, row2 with row2, and row3 with row3, then you need to just use a 1 row by 3 column kernel instead of a 3x3.
atefeh gh
2014년 9월 4일
Image Analyst
2014년 9월 4일
No I don't. I don't see why blurring the image would be preferable. Usually when people ask for image processing advice, they attach an image.
atefeh gh
2014년 9월 5일
Image Analyst
2014년 9월 5일
OK then if that's what you want, you can blur the image like this
blurredImage = conv2(double(binaryImage), ones(3)/9);
atefeh gh
2014년 9월 5일
Image Analyst
2014년 9월 5일
I think that should be the same. Sometimes there are weird things about keeping classes the same so you'd need to check that. For example t2 mgiht be uint8 instead of double and thus not show fractional numbers but just round to 0 and 1. If that happens, just cast to double before sending in to imfilter.
카테고리
도움말 센터 및 File Exchange에서 Image Segmentation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!