How to read and store pixel intensity and coordinates values of a grayscale-converted image?

122 Ansichten (letzte 30 Tage)
I have a colormap image and I convert it to gray scale using:
A=imread('Image1.jpg')
B=rgb2gray(A)
Now I want to be able to know the pixel intensities of each pixel as a function of their coordinates, or basically just stored with their coordinates such that later I can scan pixel intensities through a desired coordinate range.
I know impixel(B, xi, yi) will give me the pixel intensity that I want at (xi, yi), but where are all these single pixel intensity values are stored? And also impixel() command gives me 3 pixel intensity values, which are all the same, even though the image is grayscale, is there a way to get the single pixel intensity value of the grayscale image?
Thanks,

Antworten (1)

Divya Gaddipati
Divya Gaddipati am 16 Jul. 2019
Hi,
As I understand, you want to get the pixel intensity value of the grayscale image (B) at a particular location (xi, yi).
You can directly use the matrix row-column indexing method to get the pixel intensity value at a particular location. For example, modifying your code as follows:
A = imread('Image1.jpg')
B = rgb2gray(A)
intensity_value = B(xi, yi);
% xi, yi is the location at which you want to get the intenisty value
The “impixel” function, which you used returns the intensity value as an RGB triplet. Hence, for a grayscale image, R, G and B values obtained will be equal. For more information on how to use “impixel”, you can refer to the following documentation:
  3 Kommentare
yanqi liu
yanqi liu am 3 Mär. 2022
each location of pixel
row : y
col: x
then we cant get pixel by B(y, x)
Image Analyst
Image Analyst am 3 Mär. 2022
@YOGITAA YOGITAA I don't even know what that means. In DIvya's code A IS the color of each pixel, and B IS the "intensity" of each pixel (after the color image has been converted to gray scale). So explain why A and B are not what you want. What do you want that is different than that?
To get the intensity of a single pixel, you can specify the y (row) location first and then the x (column) location, unlike what Divya did, so you'd do
intensity_value = B(yi, xi)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by