MATLAB: How to transfer image pixel values into array

image processing

transfer image pixel values into array for complete image
  • array(,1)=R value
  • array(,2)=G value
  • array(,3)=B value
  • array(,4)=x position
  • array(,5)= y position

Best Answer

Try this:
for k = 1 : length(RValues)
array(k, 1) = RValues(k);
array(k, 2) = GValues(k);
array(k, 3) = BValues(k);
array(k, 4) = XValues(k);
array(k, 5) = YValues(k);
end
OR
% For a complete image
k = 1;
[rows, columns, numberOfColorChannels) = size(rgbImage);
if numberOfColorChannels == 3
for col = 1 : columns
for row = 1 : rows
array(k, 1) = rgbImage(row, col, 1);
array(k, 2) = rgbImage(row, col, 2);
array(k, 3) = rgbImage(row, col, 3);
array(k, 4) = col;
array(k, 5) = row;
k = k + 1;
end
end
end
I don't know why you'd ever want this unless maybe you were exporting to some kind of modeling/cadcae program.
Related Question