How to do operation on an image after making boundary?

2 次查看(过去 30 天)
I attached the input image before making boundary and output image after making boundary with matlab code. Now how to perform next operation on image with boundary?
if true
% code
% Display the binary image.
subplot(2, 2, 3);
imshow(handImage1);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2,2,4);
imshow(handImage1);
title('binary image with border');
boundaries=bwboundaries(handImage1);
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
hold on;
plot(x, y, 'black', 'LineWidth', 2);
newImage = bwlabel(handImage1);
measurements = regionprops(newImage, 'Centroid', 'BoundingBox');
xCentroid = measurements.Centroid(1);
yCentroid = measurements.Centroid(2);
figure;
imshow(newImage);
title('Binary Image with Centroid Marked');
hold on;
plot(xCentroid, yCentroid, 'r*', 'MarkerSize', 10, 'LineWidth', 2);
end
In this the problem that I am facing is that when I try to label the image for finding centroid after forming a boundary, then it performs the operation on binary image without boundary. So, the binary image with boundary is stored in which variable here?

回答(1 个)

Image Analyst
Image Analyst 2017-9-8
"when I try to label the image for finding centroid after forming a boundary, then it performs the operation on binary image without boundary." bwlabel() is operating on handImage1 so handImage1 better be a logical image, not a uint8 or color image. Also, handImage1 is the full image. I don't know what you want. What is the binary image with boundary that you would rather have it work on? Do you want to mask it? Why? Is it just to get rid of the smaller blobs, which you can do more directly with bwareafilt(), the function meant for that?
"So, the binary image with boundary is stored in which variable here?" Well, you're saying it's handImage1 because that's what you titled it when you showed it and that's what you passed in to bwboundaries().
  1 个评论
Manjiree Waikar
Manjiree Waikar 2017-9-9
if true
% code
clear all; *bold*
close all;
fontSize = 13;
rgbImage = imread(imgetfile);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
grayImage = rgb2gray(rgbImage);
% Display the image.
subplot(2, 2, 2);
imshow(grayImage);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
b = grayImage<170;
b = imfill(b, 'holes');
% Label the image
labeledImage = bwlabel(b);
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
% Let's extract the biggest blob - that will be the hand.
allAreas = [measurements.Area];
[sortedAreas, sortingIndexes] = sort(allAreas, 'descend');
handIndex1 = sortingIndexes(1);
% Use ismember() to extract the hand from the labeled image.
handImage1 = ismember(labeledImage, handIndex1);
% Now binarize
handImage1 = handImage1 > 0;
% Display the binary image.
subplot(2, 2, 3);
imshow(handImage1);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2,2,4);
imshow(handImage1);
title('binary image with border');
boundaries=bwboundaries(handImage1);
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
hold on;
plot(x, y, 'black', 'LineWidth', 2);
newImage = bwlabel(handImage1);
measurements = regionprops(newImage, 'Centroid', 'BoundingBox');
xCentroid = measurements.Centroid(1);
yCentroid = measurements.Centroid(2);
figure;
imshow(newImage);
title('Binary Image with Centroid Marked');
hold on;
plot(xCentroid, yCentroid, 'r*', 'MarkerSize', 10, 'LineWidth', 2);
end
Sir, I have attached my code and input image. I want to find centroid and hand extremeties of the segmented hand image. So, for wrist completion I tried to form a boundary. After getting wrist completion when I tried to find centroid of the hand then I got the centroid for binary image not for the image after formation of boundary(image after wrist completion). I want to solve this problem as when I go for another image (2nd image in the attachment) as input; I don't get the desired result. And my handImage is logical only. Please help with the MATLAB code for wrist completion so that I will be able to get correct centroid for hand.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by