selecting neighborhood in 2D matrix

1 次查看(过去 30 天)
xplore29
xplore29 2013-5-26
I have a 2D matrix A and a mask M with a pivot element at location (i,j). I need to select a neighborhood of an entry of A at (p,q) based on the shaped of mask. How can I place my pivot element of mask at location (p,q) in A. I can create an alias of mask with logical entries to select the neighborhood but I don't know how to first make sure that the pivot element is aligned with the (p,q) entry. Do I really need to first align the pivot element of mask with the (p,q) entry do select the neighborhood? I am not really looking for some stuff from image processing toolbox since my 2D matrix is not an image. I would appreciate if someone can suggest a general solution

回答(1 个)

Image Analyst
Image Analyst 2013-5-27
I don't know what you want to do. You're using non-standard lingo, at least as far as imaging goes. What is a pivot element? A mask is a 2D matrix of some extent, so what is it's pivot element? Which element of the mask? The center one? The upper left??? By the way, any 2D array can be considered as an image as far as the Image Processing Toolbox goes. It doesn't matter if you consider it an image, a mask, a sliding window, a kernel, or whatever you want to call it or how you interpret it.
Why don't you just say what you want to do? Like you want to mask an image, or you want to blur an image with a sliding box filter, or you want to do a hit or miss filter, or you want to do a morphological closing, or whatever.
  7 个评论
Image Analyst
Image Analyst 2013-5-27
Don't use Image as the name of a variable since it's too close to the built in function image(). I don't see any need for "Alias". You might be able to get a little more speed if you reverse the loops over i and j. Put the loop over rows inside the loop over columns since MATLAB stores memory going down a column (incrementing rows first), before it jumps to the next column. So the loop over i (rows) should be inside. Finally I'd recommend using rows and columns rather than i and j because it's clearer and more descriptive.
xplore29
xplore29 2013-5-27
but you do agree that bring the pivot element at the center of extended_mask will make sliding window more easy to handle?

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by