Info

此问题已关闭。 请重新打开它进行编辑或回答。

I have executed a code and it seem to give errors. Is there any invalid statements? The image is of [r x c] = 256 X 256 and I tried to store each co-ordinate {(1,1),(1,​2),...,(25​6,256)} corresponding to each pixel value in an array 'C'.

1 次查看(过去 30 天)
I = imread('Cameraman.tif');
[r,c] = size(I);
k = 1;
loop to store the pixel co-ordinates
for i = 1:r;
for j = 1:c;
C(k,:) = [i,j];
k = k + 1;
end
end
Expected should be: When I type C(10,10), it should return the pixel value corresponding the resp co-ordinate.
  1 个评论
Stephen23
Stephen23 2016-3-22
编辑:Stephen23 2016-3-22
You already imported the image as an array I, so why not just access it directly?, e.g.:
pixval = I(10,10,:)
Good programmers try to keep their code as simple as possible, because this makes it faster, more robust, and easier to test, easier to undestand, easier to write, easier to fix...
Why bother indirectly accessing the pixels when you can index into the image directly?
Your proposal "When I type C(10,10), it should return the pixel value corresponding the resp co-ordinate" can be achieved in one step using num2cell, but this is a total waste of time.

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by