Finding neighboring pixels surrounding a region/patch
7 次查看(过去 30 天)
显示 更早的评论
Hello Dear Community.
After trying and searching a lot, I ultimately have to put the question here. I need to find the neighbor pixels. For example, I have a random 3x3 neighborhood/patch/region and I want to find the outer pixels (pixels right next to the patch) that surrounds this patch. Once, I find all these outer pixels (which will be 16 pixels in this case), I'll choose one among these 16 pixels. Now, I have another a random patch (not squared patch as it has 3x3 + 1 pixels). Then, I want to apply the same steps i.e., find the outer pixels surrounding this non-squared region and choose one pixel among them and make another random non-squared patch, and so on... It's a kind of region/pixel growing but not exactly region growing. Can anyone help on this? Many thanks.
2 个评论
Image Analyst
2017-1-17
I don't understand " Now, I have another a random patch (not squared patch as it has 3x3 + 1 pixels)" Exactly how many pixels wide and tall is it? And where is its location with respect to the first random region? And what help do you want? Is this a "Do it all for me" situation? You know how to extract a n-by-m submatrix from a larger matrix using indexing, and how to use randi(), don't you?
回答(1 个)
Image Analyst
2017-1-17
" I have any random shaped patch with lets say 10 pixels, how do I get the locations of the pixels surrounded by that random-shaped patch?"
Use imdilate() to dilate out that patch by one layer of pixels, then use bwperim to get the values. Use it as a mask if you don't care what order they are in. Otherwise you'd have to specify a starting pixel and direction (clockwise or counter clockwise). Briefly, to get you started, if originalImage is the image of values and binaryImage is an image where it's true where your initial patch is and false where the patch isn't, then ...
dilatedImage = imdilate(binaryImage, true(3));
borderPixels = bwperim(dilatedImage);
pixelValues = originalImage(borderPixels);
2 个评论
Piyum Rangana
2017-2-12
Could you please explain 'originalImage()' function, that was used in the last row of above answer that it is an inbuilt function or not ?
Image Analyst
2017-2-12
originalImage is a matrix variable. It's the name of your original image. I'm sure you didn't call it "originalImage" like I did, so what did you call it? Hopefully not I or A or some other cryptic, non-descriptive name. Just substitute your actual variable name for originalImage.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!