??? Attempt to reference field of non-structure array. Error in ==> Untitled2 at 36 binaryImage = hFH.createMask();
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
% Demo to have the user freehand draw an irregular shape over
% a gray scale image, and burn the curve points into the image.
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 = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% 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.
message = sprintf('Left click and hold to begin drawing.\nSimply lift the mouse button to finish');
uiwait(msgbox(message));
hFH = imfreehand(gca);
% Create a binary image ("mask") from the ROI object.
binaryImage = hFH.createMask();
xy = int32(hFH.getPosition);
% Now make it smaller so we can show more images.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Display the freehand mask just for fun - we won't use binaryImage.
binaryImage = false(size(grayImage));
linearIndexes = sub2ind(size(grayImage), xy(:, 2), xy(:, 1));
binaryImage(linearIndexes) = true;
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary mask of the region', 'FontSize', fontSize);
% Display it.
subplot(2, 2, 3);
grayImage(linearIndexes) = 255;
imshow(grayImage);
axis on;
title('Grayscale Image with freehand curve burned in', 'FontSize', fontSize);
I am new to MATLAB, and want to find out the pixel value of a particular region, so i simply copy n paste ur code an found an error
??? Attempt to reference field of non-structure array.
Error in ==> Untitled2 at 36
binaryImage = hFH.createMask();
Kindly help me to remove it.
1 Kommentar
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!