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

120 ビュー (過去 30 日間)
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,

回答 (1 件)

Divya Gaddipati
Divya Gaddipati 2019 年 7 月 16 日
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 件のコメント
yanqi liu
yanqi liu 2022 年 3 月 3 日
each location of pixel
row : y
col: x
then we cant get pixel by B(y, x)
Image Analyst
Image Analyst 2022 年 3 月 3 日
@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)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by