How can i extract numerical intensity values from an image

13 views (last 30 days)
Consider an image sample.jpg Now I want to extract numerical value of pixel intensity for every pixel and the pixel location on the X and y axis such that I will have three columns X location y location and their corresponding pixel intensity. Please can someone help me with a code or a direction on how I can accomplish this?

Accepted Answer

Rik
Rik on 20 May 2019
You can make use of the fact that an image is already a matrix. Instead of ndgrid (as used in this code), you could also consider using fullfact (although that requires the statistics toolbox).
%generate a random image to make this code run
IM=uint8(randi(255,10,5));
%note that the convention is to have the y-axis flipped in images
[Y,X]=ndgrid(1:size(IM,1),size(IM,2):-1:1);
%convert the intensity to double to make sure the entire table is a double,
%which allows x and y to be greater than 255
data=[X(:),Y(:),double(IM(:))];

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!