Indexing through pixel neighbors

1 次查看(过去 30 天)
James
James 2014-9-29
I'm working on implementing linear filtering without using the imfilter or conv2 function in matlab. Rather than use for loops since I was told it would be slow to do so, I was told to take the average of the neighboring pixels. However, I was confused when given this information:
"f(i-1, j) is f that shifts by 1 pixel to the right" (f represents a pixel in an image) (I need clarification to understand why this is so, because I thought i represents the row in which the pixel is located, so I'm not sure how f(i-1, j) is a pixel shifted to the right.
Furthermore, to implement f(i-1, j) I was told to write it like so: "fright = [f(:,1), f(:, 1:end-1)];" (I'm not sure how this translates to shifting the pixel to the right.)
--If anyone can clarify this notation that would be great.

回答(2 个)

Stephen23
Stephen23 2014-9-29
编辑:Stephen23 2014-9-29
According to MATLAB's own documentation and explanations , the first index correlates to the row, and the second to the column. From the documentation:
A(row, column)
But it seems like the answer depends on what is shifted to the right: the raw data, or our view (indexing) of it? Take a close look at:
fright = [f(:,1), f(:, 1:end-1)];
This looks quite similar to a circshift of the pixel data, except that the final pixels get thrown away. Perhaps they meant:
fright = [f(:,end), f(:, 1:end-1)];
?
Probably the best idea would be to try it with some fake image data, and use the debugging tools to see how fright changes.

Image Analyst
Image Analyst 2014-9-29
If you're not using imfilter() and not using conv2() and not using for loops, then I don't know what you are using and how you can do this. Anyway, for loops are not slow. You can do tens of millions of iterations in less than a second. For loops often get a bad rap when it's actually the memory access for large arrays that can eat up the time. To reduce that, make sure that rows are the inner most loop and columns are the outer loop.
Anyway, yes, f(i-1,j) is one pixel above, not to the right like your reference said. The only thing I can figure is that they made the common mistake of confusing (x,y) with (row,column). If they thought the first index was x, that would lead to their saying that it's one pixel to the left (though you said they said right, not left). So it's not f(x,y) but rather f(y, x) since y is row and x is column.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by