How to get the entropy of an image in matlab?

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by