How to get the entropy of an image in matlab?

6 ビュー (過去 30 日間)
jabani Joseph
jabani Joseph 2020 年 12 月 10 日
回答済み: Image Analyst 2020 年 12 月 10 日
Please i'm trying to get the entropy of an image in matlab. This was the code i used but i'm still getting error.
Can anyone help?
A=imread('cameraman.tif');
size(A)
A=rgb2gray(A);
B=imresize(A, [64 64]);
size(B)
C=entropy(B);

回答 (1 件)

Image Analyst
Image Analyst 2020 年 12 月 10 日
You should only call rgb2gray() on an RGB image, not one that is already gray scale. See below for corrected and improved code:
% Read in the image from disk.
grayImage=imread('cameraman.tif');
% Display the image.
subplot(1, 2, 1);
imshow(grayImage);
axis('on', 'image');
title('Original Image');
impixelinfo;
% Convert to gray scale but only if needed.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
% Resize the image.
resizedImage = imresize(grayImage, [64, 64]);
% Display the image.
subplot(1, 2, 2);
imshow(resizedImage, 'InitialMagnification', 400);
axis('on', 'image');
title('Resized Image');
impixelinfo;
[rows2, columns2, numberOfColorChannels2] = size(resizedImage)
% Compute the entropy of the whole image.
% If you want local entropy, use entropyfilt().
totalEntropy = entropy(resizedImage);
message = sprintf('The entropy of the image is %f.', totalEntropy);
fprintf('%s\n', message);
msgbox(message);

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by