Plotting histogram of image data present in a stack

Hi All,
I have looked at the examples shown here to underetand how to plot histogram of a single image data. But
it's not clear to me how the data in a stack can be plotted.
For exmaple, I tried
f = "Test_Image.tiff";
img_data = imfinfo(f);
imhist(img_data)
test_image stack.
This returns
double, uint8, int8, logical, uint16, int16, single, uint32, int32
Instead its type was struct.
Any suggestions?

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日

0 投票

iminfo just read the metadata of the image. Use imread() to read the image as matrix
f = "Test_Image.tiff";
img_data = imread(f);
imhist(img_data)
If it is an rgb image, then first convert it to grayscale too
f = "Test_Image.tiff";
img_data = rgb2gray(imread(f));
imhist(img_data)

6 件のコメント

Deepa Maheshvare
Deepa Maheshvare 2020 年 10 月 14 日
編集済み: Deepa Maheshvare 2020 年 10 月 14 日
Could you please let me know if `imread()` can be used to read an image stack? I have tested it before and it reads only the first image of the stack which is also mentioned in the documentation (https://in.mathworks.com/help/matlab/ref/imread.html?s_tid=srchtitle)
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
Yes, you can use
img_data = imread(f, 'all');
to read all frames. But then how to you want to do imhist()? Do you want to plot histogram of each image individually.
Deepa Maheshvare
Deepa Maheshvare 2020 年 10 月 14 日
編集済み: Deepa Maheshvare 2020 年 10 月 14 日
"But then how to you want to do imhist()? Do you want to plot histogram of each image individually".
No, I would like to generate the histogram in a single plot. May I know how to do this?
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
Try this
f = "Test_Image.tiff";
img_data = imfinfo(f);
imgs = cell(1, numel(img_data));
for i = 1:numel(img_data)
imgs{i} = imread(f, i);
end
imgs = cat(3, imgs{:});
imhist(imgs(:))
Deepa Maheshvare
Deepa Maheshvare 2020 年 10 月 14 日
Thanks a lot. This helps! I would also like to know if it is possible to get the stats like mean, sd, mode, binwidth (I checked that the default bin is 256) , min and max and count?
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
By default imhist() uses 256 bins. You can get the counts using output of imhist()
[binCount, binLoc] = imhist(imgs(:));
To get min and max values
mean(imgs(:))
min(imgs(:))
max(imgs(:))

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by