how to get value of all pixel in grayscale image?

 Réponse acceptée

You specify the row and column:
grayImage = imread(filename);
% Find intensity at row 5, column 39:
thisIntensity = grayImage(5, 39);
% or
thisIntensity = impixel(grayImage, 5, 39);
You might also like to mouse around over the image and see a "live" interactive readout of the x, y, and intensity. If so, do this:
hp = impixelinfo();
You can then place it where like by doing
hp.Position = [x, y, width, height];

8 commentaires

can i get all of the pixel in 1 time?
Rik
Rik le 26 Nov 2017
Yes, the values are inside the grayImage variable.
he meant how to do it from all the pixels in the image all in one
@Luis Fernandez. I have no idea what you said. All the pixels in the image are in one variable. If that's what you/he wants, there is nothing left to do since it is already like that.
To get the value of one single pixel, you can use row and column indexing
onePixelsValue = grayImage(row, column);
I think he wants to get a table with columns [X Y Grayscale] so he can look at every single pixel with its grayscale value.
@Luis Fernandez, well that would be a most inefficient way of doing it. But you can create a table if you want
grayImage = imread('cameraman.tif');
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels == 3
grayImage = rgb2gray(grayImage);
end
% Resize to 5x5 to make the image and table smaller for demo purposes.
% grayImage = imresize(grayImage, [5, 5]);
% [rows, columns, numberOfColorChannels] = size(grayImage)
% Get list of all rows and columns.
[r, c] = meshgrid(1:rows, 1:columns); % or [y, x] instead of [r, c]
t = table(c(:), r(:), grayImage(:), 'VariableNames', {'RowNumber', 'Column', 'GrayLevel'})
or you can just create a 2-D double array instead of a table:
xyGL = [c(:), r(:), double(grayImage(:))] % Each row is x, y, gray level. c = column = x
Thanks its working. But I want to plot grayvalues and pixel. From that graph I want to get gaussian curve. Could you help me with it ?
Sure. Did you use the plot() function? And what do you think the difference is between "grayvalues" and "pixel"??? The value of a pixel is its gray level. And the gray levels are what they are, and they may not be the Gaussian curve you're expecting.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Read, Write, and Modify Image dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by