How to display contrast image, entropy image, homogeneity image ... ?

조회 수: 3 (최근 30일)
Johanna THAI
Johanna THAI 2021년 6월 14일
댓글: Johanna THAI 2021년 6월 15일
Hello,
I have this code which shows the values. But how to display the images ? Like that https://imgur.com/mewPK,FLldQ
THank you
glcm=graycomatrix(croppedImage);
F=graycoprops(glcm,{'Contrast','Homogeneity','Correlation','Energy'});
contrast=F.Contrast;
homogeneity=F.Homogeneity;
correlation=F.Correlation;
energy=F.Energy;
entropie = entropy(croppedImage);
res=[contrast energy homogeneity correlation entropie]

답변 (1개)

Sanchit Trivedi
Sanchit Trivedi 2021년 6월 15일
편집: Sanchit Trivedi 2021년 6월 15일
You can use the subplot function to show images in a grid. Specify the subplot you want to use and follow it up with the imshow function.
subplot(2,2,1)
imshow(<Image>)
For more details on the subplot function you can refer to the documentation.
  댓글 수: 3
Sanchit Trivedi
Sanchit Trivedi 2021년 6월 15일
Passing scalar values instead of an Image Matrix to imshow is causing this issue. Try passing in the Image Matrices for the task that you are trying to accomplish.
Johanna THAI
Johanna THAI 2021년 6월 15일
How can I do that ?
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fileparts(which('FAtest.jpg')); % Determine where demo folder is.
baseFileName = 'FAtest.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Ask user to draw freehand mask.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand(); % Actual line of code to do the drawing.
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
xy = hFH.getPosition;
% Now make it smaller so we can show more images.
subplot(2, 4, 1);
imshow(grayImage, []);
axis on;
drawnow;
title('Original gray scale image', 'FontSize', fontSize);
% Display the freehand mask.
subplot(2, 4, 2);
imshow(binaryImage);
axis on;
title('Binary mask of the region', 'FontSize', fontSize);
% Label the binary image and computer the centroid and center of mass.
labeledImage = bwlabel(binaryImage);
measurements = regionprops(binaryImage, grayImage, ...
'area', 'Centroid', 'WeightedCentroid', 'Perimeter');
area = measurements.Area
centroid = measurements.Centroid
centerOfMass = measurements.WeightedCentroid
perimeter = measurements.Perimeter
% Calculate the area, in pixels, that they drew.
numberOfPixels1 = sum(binaryImage(:));
% Another way to calculate it that takes fractional pixels into account.
numberOfPixels2 = bwarea(binaryImage);
% Get coordinates of the boundary of the freehand drawn region.
structBoundaries = bwboundaries(binaryImage);
xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates.
x = xy(:, 2); % Columns.
y = xy(:, 1); % Rows.
subplot(2, 4, 1); % Plot over original image.
hold on; % Don't blow away the image.
plot(x, y, 'LineWidth', 2);
drawnow; % Force it to draw immediately.
% Burn region as white into image by setting it to 255 wherever the mask is true.
burnedImage = grayImage;
burnedImage(binaryImage) = 255;
% Display the image with the mask "burned in."
subplot(2, 4, 3);
imshow(burnedImage);
axis on;
caption = sprintf('Masked white inside region');
title(caption, 'FontSize', fontSize);
% Burn region as black into image by setting it to 255 wherever the mask is true.
burnedImage = grayImage;
burnedImage(binaryImage) = 0;
% Display the image with the mask "burned in."
subplot(2, 4, 4);
imshow(burnedImage);
axis on;
caption = sprintf('Masked black inside region');
title(caption, 'FontSize', fontSize);
% Mask the image white outside the mask, and display it.
% Will keep only the part of the image that's inside the mask, white outside mask.
whiteMaskedImage = grayImage;
whiteMaskedImage(~binaryImage) = 255;
subplot(2, 4, 5);
imshow(whiteMaskedImage);
axis on;
title('Masked white outside region', 'FontSize', fontSize);
% Mask the image outside the mask, and display it.
% Will keep only the part of the image that's inside the mask, zero outside mask.
blackMaskedImage = grayImage;
blackMaskedImage(~binaryImage) = 0;
subplot(2, 4, 6);
imshow(blackMaskedImage);
axis on;
title('Masked black outside region', 'FontSize', fontSize);
% Calculate the mean
meanGL = mean(blackMaskedImage(binaryImage));
sdGL = std(double(blackMaskedImage(binaryImage)));
% Put up crosses at the centroid and center of mass.
hold on;
plot(centroid(1), centroid(2), 'r+', 'MarkerSize', 30, 'LineWidth', 2);
plot(centerOfMass(1), centerOfMass(2), 'g+', 'MarkerSize', 20, 'LineWidth', 2);
% Now crop the image.
leftColumn = min(x);
rightColumn = max(x);
topLine = min(y);
bottomLine = max(y);
width = rightColumn - leftColumn + 1;
height = bottomLine - topLine + 1;
croppedImage = imcrop(blackMaskedImage, [leftColumn, topLine, width, height]);
% Display cropped image.
% subplot(2, 4, 7:8);
figure(7)
imshow(croppedImage);
axis on;
title('Cropped image', 'FontSize', fontSize);
% Put up crosses at the centroid and center of mass.
hold on;
plot(centroid(1)-leftColumn, centroid(2)-topLine, 'r+', 'MarkerSize', 30, 'LineWidth', 2);
% text(centroid(1)-leftColumn + 20, centroid(2)-topLine-20, 'Centroid', 'Color', 'r');
plot(centerOfMass(1)-leftColumn, centerOfMass(2)-topLine, 'g+', 'MarkerSize', 20, 'LineWidth', 2);
% text(centroid(1)-leftColumn + 20, centroid(2)-topLine+20, 'Weighted Centroid', 'Color', 'g');
% Report results.
message = sprintf('Mean value within drawn area = %.3f\nStandard deviation within drawn area = %.3f\nNumber of pixels = %d\nArea in pixels = %.2f\nperimeter = %.2f\nCentroid at (x,y) = (%.1f, %.1f)\nCenter of Mass at (x,y) = (%.1f, %.1f)\nRed crosshairs at centroid.\nGreen crosshairs at center of mass.', ...
meanGL, sdGL, numberOfPixels1, numberOfPixels2, perimeter, ...
centroid(1), centroid(2), centerOfMass(1), centerOfMass(2));
msgbox(message);
glcm=graycomatrix(croppedImage);
F=graycoprops(glcm,{'Contrast','Homogeneity','Correlation','Energy'});
contrast=F.Contrast;
homogeneity=F.Homogeneity;
correlation=F.Correlation;
energy=F.Energy;
entropie = entropy(croppedImage);
I have this code which allows me to cut out my ROI which name is "croppedImage".
Idk how to display the images.
Thankyou for your kindly help

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by