how to find pixel values and intensity of grayscale image and plot them (x-axis as pixel value and y-axis as pixel intensity)
Show older comments
I have an grayscale image with values ranging from -0.86 to 0.53. I want to extract pixel values of whole image and intensity of each pixel and plot them. The x axis should be pixel value and y-axis should be intensity and the x-axis interval is 0.2.
I got some solutions before to store pixel values by impixel but it store values according to row and column. Can anyone help me in this matter.
3 Comments
DGM
on 3 Oct 2023
Define "pixel value" and "intensity". You're clearly making some distinction, but if you just have 2D data, then that's it. You have one metric. If there is some presumed fixed relationship between the two, then that information is unclear from the given information. It's also unclear why you'd want or need to plot it if the relationship were already fixed and known.
(replying to a comment that doesn't exist anymore)
If you want a histogram, then I don't see why the distinction between value and intensity is relevant. It's still not clear that it even exists.
% some arbitrarily-scaled array
A = randn(100) + 4*randi([0 1],100,100);
% displayed with scaled colormapping
imshow(A,[])
% show the histogram
figure
h = histogram(A);
If you want the bin edges and counts, you can either get that information from the histogram object h, or you can use histcounts() instead.
Image Analyst
on 3 Oct 2023
I agree with @DGM - pixel value and pixel intensity are the same thing (to everyone except you). It makes no sense to plot one vs the other. Clarify not only what (you think) you need but why you want it (in other words what will you do with that information once you have it)
Accepted Answer
More Answers (2)
Tanmoyee Bhattacharya
on 4 Oct 2023
Edited: Tanmoyee Bhattacharya
on 4 Oct 2023
0 votes
Image Analyst
on 5 Oct 2023
I'm not sure why you're taking a histogram of the binary image. I think what you meant was to take the histogram of the masked part of the image, so why don't you try this:
grayImage = imread('E:\waterbody_project\processed_sen\mnwi.tif');
mask = grayImage < 255; % Non white parts only.
histogram(grayImage(mask));
Categories
Find more on Blue in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






