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),...,(256,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
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!