Azzera filtri
Azzera filtri

How to plot a histogram from 0-255

4 visualizzazioni (ultimi 30 giorni)
Changoleon
Changoleon il 6 Set 2016
Commentato: Guillaume il 11 Set 2017
I use img1=imread function to load my image into matlab. The image is 512by512 and the intensity range is 0-255. However the histogram of my image ( which I use imhist(img1) to plot it) has values only at 0 and 1. How is that? I mean when I take a look at the array of my picture, I see numbers varying from 0-255. Is it because I am using imhist? Any idea would be appreciated. and sorry if the question might be very basic for some of you.

Risposta accettata

Thorsten
Thorsten il 6 Set 2016
Modificato: Thorsten il 6 Set 2016
I = imread('cameraman.tif');
imhist(I)
shows values from 0 to 255. Do you change I after imread and before imhist?
  2 Commenti
Changoleon
Changoleon il 6 Set 2016
actualy this is how I code: a = double(imread('Wk1_O5_Image017.tif')); is it double?
Thorsten
Thorsten il 6 Set 2016
Either use
I = imread('yourfile.tif');
imhist(I);
or as Guillaume suggests,
I = im2double(imread('yourfile.tif'));
imhist(I)

Accedi per commentare.

Più risposte (2)

Guillaume
Guillaume il 6 Set 2016
Most image processing functions expect double images to be in the range 0-1. If the range is 0-255, matlab expects it to be a uint8 image.
a = im2double(imread('yourimage'));
imhist(a);
should solve your problem. Or keep the image as uint8.

dhafer alhajim
dhafer alhajim il 11 Set 2017
Modificato: dhafer alhajim il 11 Set 2017
if you want the value and the range from 0 to 255 a = im2double(imread('your image')); h=uint8(imhist(a));
  1 Commento
Guillaume
Guillaume il 11 Set 2017
@dhifer alhajm
I don't see the point in answering a question that is over a year old. Particularly as your answer is totally incorrect. Because of the call to im2double, the input range is 0-1. As for the uint8(imhist), that's completely silly, any histogram count above 255 will be clamped to 255.
Here's an example:
a = uint8(repelem([0 63 127 255]', [20 40 60 80], 200));
imshow(a);
This is an image with 4000 counts of intensity 0, 8000 of intensity 63, 12000 of intensity 127 and 16000 counts of intensity 255.
>>h = uint8(imhist(im2double(a)))
>>h(1) %counts of intensity 0
ans =
255
>>h(end) %count of intensity 255
ans =
255
The count of all intensities present in the image is 255 according to you.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by