Drawing the major and minor axis of an elliptical object in Matlab
This program currently inputs an image of a coin, thresholds it, binarizes it, and finds the major and minor axis lengths of the segmented elliptical using the regionprops function. What I want to do is output a subplot where I draw the axes used to calculate the ‘MajorAxisLength’ and ‘MinorAxisLength’ over the original image. Would really appreciate help with this.
I have appended the code for your perusal.
rgbImage = imread(coin2.jpg);
subplot(2, 3, 1);
imshow(rgbImage, []);
title(‘Original Image’);
redChannel = rgbImage(:, :, 1);
binaryImage = redChannel < 100;
subplot(2, 3, 3);
imshow(binaryImage, []);
title(‘Binarized Image’);
labeledImage = bwlabel(binaryImage);
area_measurements = regionprops(labeledImage,’Area’);
allAreas = [area_measurements.Area];
biggestBlobIndex = find(allAreas == max(allAreas));
keeperBlobsImage = ismember(labeledImage, biggestBlobIndex);
measurements = regionprops(keeperBlobsImage,’MajorAxisLength’,’MinorAxisLength’)
% Display the original color image with outline.
subplot(2, 3, 4);
imshow(rgbImage);
hold on;
title(‘Original Color Image with Outline’, ‘FontSize’,fontSize);
boundaries = bwboundaries(keeperBlobsImage);
blobBoundary = boundaries{1};
plot(blobBoundary(:,2), blobBoundary(:,1), ‘g-‘, ‘LineWidth’, 1);
hold off;This program currently inputs an image of a coin, thresholds it, binarizes it, and finds the major and minor axis lengths of the segmented elliptical using the regionprops function. What I want to do is output a subplot where I draw the axes used to calculate the ‘MajorAxisLength’ and ‘MinorAxisLength’ over the original image. Would really appreciate help with this.
I have appended the code for your perusal.
rgbImage = imread(coin2.jpg);
subplot(2, 3, 1);
imshow(rgbImage, []);
title(‘Original Image’);
redChannel = rgbImage(:, :, 1);
binaryImage = redChannel < 100;
subplot(2, 3, 3);
imshow(binaryImage, []);
title(‘Binarized Image’);
labeledImage = bwlabel(binaryImage);
area_measurements = regionprops(labeledImage,’Area’);
allAreas = [area_measurements.Area];
biggestBlobIndex = find(allAreas == max(allAreas));
keeperBlobsImage = ismember(labeledImage, biggestBlobIndex);
measurements = regionprops(keeperBlobsImage,’MajorAxisLength’,’MinorAxisLength’)
% Display the original color image with outline.
subplot(2, 3, 4);
imshow(rgbImage);
hold on;
title(‘Original Color Image with Outline’, ‘FontSize’,fontSize);
boundaries = bwboundaries(keeperBlobsImage);
blobBoundary = boundaries{1};
plot(blobBoundary(:,2), blobBoundary(:,1), ‘g-‘, ‘LineWidth’, 1);
hold off; This program currently inputs an image of a coin, thresholds it, binarizes it, and finds the major and minor axis lengths of the segmented elliptical using the regionprops function. What I want to do is output a subplot where I draw the axes used to calculate the ‘MajorAxisLength’ and ‘MinorAxisLength’ over the original image. Would really appreciate help with this.
I have appended the code for your perusal.
rgbImage = imread(coin2.jpg);
subplot(2, 3, 1);
imshow(rgbImage, []);
title(‘Original Image’);
redChannel = rgbImage(:, :, 1);
binaryImage = redChannel < 100;
subplot(2, 3, 3);
imshow(binaryImage, []);
title(‘Binarized Image’);
labeledImage = bwlabel(binaryImage);
area_measurements = regionprops(labeledImage,’Area’);
allAreas = [area_measurements.Area];
biggestBlobIndex = find(allAreas == max(allAreas));
keeperBlobsImage = ismember(labeledImage, biggestBlobIndex);
measurements = regionprops(keeperBlobsImage,’MajorAxisLength’,’MinorAxisLength’)
% Display the original color image with outline.
subplot(2, 3, 4);
imshow(rgbImage);
hold on;
title(‘Original Color Image with Outline’, ‘FontSize’,fontSize);
boundaries = bwboundaries(keeperBlobsImage);
blobBoundary = boundaries{1};
plot(blobBoundary(:,2), blobBoundary(:,1), ‘g-‘, ‘LineWidth’, 1);
hold off; matlab, image-processing MATLAB Answers — New Questions