Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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 Ansicht (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 22 Mär. 2016
Bearbeitet: Stephen23 am 22 Mär. 2016
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.

Antworten (0)

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by