I dont know what does this means,

1 view (last 30 days)
Shoaib Akhtar
Shoaib Akhtar on 19 Jul 2012
Plot the MPP for each image.
  1 Comment
Sean de Wolski
Sean de Wolski on 19 Jul 2012
Neither do I. And I am guessing Google's first few results aren't what you are looking for.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 20 Jul 2012
I have code for a "restricted convex hull" and include demo code for that below. It's like the convex hull but allows the hull to follow the outline into some concave parts of the shape. You specify a parameter that says how tightly the shape hugs the actual outline.
% function RestrictedConvexHull()
% http://www.liacs.nl/~fverbeek/courses/iammv/scil_ref.pdf
% Demo to have the user click a bunch of vertex points and compute the restricted convex hull of those points.
% DESCRIPTION
% Calculate a restricted convex hull of each object in the image "in" and store
% the result in image "out". For each object in "in", all combinations of two contour
% points with Euclidean distance less than or equal to "dist", are connected by a straight
% line. If a background pixel is found on such a line, it is added to the original object.
% This operation closes all holes in an object which are less than "dist" wide. The
% contour of an object is also smoothed, because gaps with a length less than "dist" are
% completely filled.
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 = 14;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.
set(gcf,'name','Spline Demo by ImageAnalyst','numbertitle','off')
grayImage = zeros(240,320);
subplot(2,2,1);
imshow(grayImage);
axis on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Your Points', 'FontSize', fontSize);
hold on
% Initially, the list of points is empty.
knots = [];
numberOfPointsClicked = 0;
% Prompt the user
message = sprintf('Left click to draw some vertex points in a "C" or "U" shape.\nRight click the final point to finish drawing.');
uiwait(msgbox(message));
buttonThatWasClicked = 1;
% Enter a loop asking user to click on the know vertexes.
while buttonThatWasClicked == 1
[xKnot, yKnot, buttonThatWasClicked] = ginput(1);
plot(xKnot, yKnot, 'ro', 'LineWidth', 2)
numberOfPointsClicked = numberOfPointsClicked+1;
% Make this coordinate a new column.
knots(:, numberOfPointsClicked) = [xKnot; yKnot];
end
% Find all the distances between any point and any other point.
subplot(2,2,2);
set(gca,'YDir','reverse'); % Flip upside down so chart matches image.
numberOfLines = 0;
for k1 = 1 : numberOfPointsClicked
%----- Burn line into image -----
% Create line mask, h, as an ROI object over the second image in the bottom row.
x1 = knots(1, k1);
y1 = knots(2, k1);
for k2 = k1 + 1 : numberOfPointsClicked
x2 = knots(1, k2);
y2 = knots(2, k2);
numberOfLines = numberOfLines + 1;
distance = sqrt((x2-x1) ^ 2 + (y2-y1) ^ 2);
distances(numberOfLines) = distance;
plot([x1 x2], [y1 y2], 'r-');
hold on;
end
end
set(gca,'YDir','reverse'); % Flip upside down so chart matches image.
% Display all the lines.
title('All Possible Lines Between All Points', 'FontSize', fontSize);
% Now get a histogram of the distances.
[count, distanceValues] = hist(distances);
subplot(2,2,3);
bar(distanceValues, count);
title('Histogram of distances between lines', 'FontSize', fontSize);
drawnow;
% Have user indicate the distance
subplot(2,2,1); % Switch current axes to the upper left one.
userPrompt = sprintf('In the upper left image, indicate the longest distance between points that you would like to connect.\nLeft click the first point.\nRight click the second point.');
reply = questdlg(userPrompt,'Continue?', 'OK','Cancel', 'OK');
% reply = '' for Upper right X, 'OK','' for OK',', 'Cancel' for Cancel.
if strcmpi(reply, 'Cancel') || strcmpi(reply, '')
return;
end
% Get the coordinates.
[xCoords yCoords lineProfile] = improfile;
plot([xCoords(1) xCoords(end)], [yCoords(1) yCoords(end)], 'y-', 'LineWidth', 2); % Show the line again on the image (improfile doesn't leave it up there.)
minDistance = sqrt((xCoords(end) - xCoords(1)) ^ 2 + (yCoords(end) - yCoords(1)) ^ 2);
userPrompt = sprintf('The distance you specified is %.1f pixels.\nClick OK to compute the restricted convex hull.', minDistance);
reply = questdlg(userPrompt,'Continue?', 'OK','Cancel', 'OK');
% reply = '' for Upper right X, 'OK','' for OK',', 'Cancel' for Cancel.
if strcmp(reply, 'Cancel')
return;
end
% Calculate the restricted convex hull
binaryImage = false(size(grayImage));
subplot(2,2,3);
imshow(binaryImage);
indexesToKeep = [];
for k1 = 1 : numberOfPointsClicked
x1 = knots(1, k1);
y1 = knots(2, k1);
for k2 = k1 + 1 : numberOfPointsClicked
x2 = knots(1, k2);
y2 = knots(2, k2);
distance = sqrt((x2-x1) ^ 2 + (y2-y1) ^ 2);
if distance > minDistance
continue;
end
indexesToKeep = [indexesToKeep k1 k2];
hLine = imline(gca,[x1 x2],[y1 y2]); % Second argument defines line endpoints.
% Create a binary image ("mask") from the ROI object.
binaryImage2 = hLine.createMask();
% Burn line into image by setting it to 255 wherever the mask is true.
binaryImage(binaryImage2) = true;
end
end
% Plot just the lines of the restricted convex hull.
subplot(2,2,3);
imshow(binaryImage, []);
caption = sprintf('Restricted Convex Hull Image with only lines shorter than %.1f', minDistance);
title(caption, 'FontSize', fontSize);
% Fill in the image to get a solid mask representing the restricted convex hull
subplot(2,2,4);
filledImage = imfill(binaryImage, 'holes');
imshow(filledImage, []);
title('Filled Restricted Convex Hull Image', 'FontSize', fontSize);
% Remove duplicates.
indexesToKeep = unique(indexesToKeep);
% Extract out just the restricted convex hull vertices from the list of all of them.
rchVertices = knots(:, indexesToKeep);
% Plot them in the original image.
subplot(2,2,1);
x = rchVertices(1, :);
y = rchVertices(2, :);
plot(x, y, 'gs');
uiwait(msgbox('Done with this Restricted Convex Hull demo!'));
There is also something called "concave hull" http://www.concavehull.com/home.php?main_menu=2 I haven't used it but from the pictures it looks similar to alpha shapes http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html

Walter Roberson
Walter Roberson on 19 Jul 2012
minimum perimeter polygon
  9 Comments
Image Analyst
Image Analyst on 20 Jul 2012
Fairly new to me too. But your latest description kind of sounds to me like a type of snake (active contour) that I've heard called "balloons." With that, it's like you have an inflatable balloon in your background and you start to blow it up. As it inflates, it will get closer and closer to the object perimeter but not go inside. The less you inflate it the less closely it hugs the object perimeter and the more you inflate the balloon the closer it gets and more closely fills the nooks and crannies of the object perimeter. It's a way of getting a smoothed perimeter of objects. Useful if you know the perimeter should be smooth, like for most internal human organs.
Image Analyst
Image Analyst on 20 Jul 2012
After looking at the diagram some more, it looks like the polygon in the "MPP" concept is constrained to lie internal to the pixels. The lines don't leave the boudnaries of the pixels, if you consider each pixel like a box. You see where you can draw a straight line within the existing boundary pixels and keep track of those polygons (most will be lines I would think). This is different than other methods where you will get new, smoother perimeters that have new pixels different than the original pixels.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!