Help with reading the RGB value of every pixel of a truecolor image using impixel

2 次查看(过去 30 天)
Hi, I have a 16bit tiff that I want to get the RGB value from each pixel in the image. The image is a 3840x2160 16bit tiff. So, I ran the impixel command:
I= imread('sample.tif');
c = [1:3840,];
r = [1:2160,];
impixel(I,c,r)
but I get this error:
Error using impixel>parse_inputs (line 257)
Xi and Yi must have the same length.
Error in impixel (line 76)
[a,cm,xi,yi,x,y] = parse_inputs(varargin{:});
Error in pixel_get (line 4)
impixel(I,c,r)
Am I doing something wrong with the syntax for column or range? Or do you suggest doing this a different way?
Thanks

采纳的回答

Veda Upadhye
Veda Upadhye 2017-11-14
Hi,
The error indicates that the vectors 'c' and 'r' should have the same length.
According to the documentation of impixel (https://www.mathworks.com/help/images/ref/impixel.html),
"impixel(I,c,r) returns the values of pixels specified by the row and column vectors r and c. r and c must be equal-length vectors. The kth row of P contains the RGB values for the pixel (r(k),c(k))."
For example, the following modification in your code would work.
I= imread('sample.tif');
c = [1:2160];
r = [1:2160];
impixel(I,c,r)
Hope this helped!
-Veda
  1 个评论
ChickenHunter
ChickenHunter 2017-11-14
Thanks for the tip Veda! I got just around the equal length requirement by running the command on each row & column of the image and then dumping the output to a file. For example for row 200:
A = imread('Sample.tif');
[r_A c_A not_used]=size(A)
r=200*ones(1,c_A)
c=[1:c_A]
T = impixel(A,c,r);dlmwrite('sample.txt', T);
I wonder if there is a better way to read each pixel value of an image. I am essentially trying to look at the pixels values of two identical images (with a slight color change) and then doing a DeltaE2000 of each pixel.

请先登录,再进行评论。

更多回答(1 个)

Chris Loizou
Chris Loizou 2017-11-13
Hello,
yes well you are doing something wrong with sintax. Remove the comma from the brackets
if true
I= imread('sample.tif');
c = [1:3840];
r = [1:2160];
impixel(I,c,r)
end

标签

Community Treasure Hunt

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

Start Hunting!

Translated by