# 代写ruby小程序matlab代做C++/python/php留学生设计安卓代码编程

function [Boundary, Area] = Extract_region (Image_given, Min_area)
% Extract_region - given Initial_value (a pixel close to the actual
% boundary of a segment), and Image containing the segment,
% outputs the supposed boundary of the piece (not necessarily connected)
% by finding the connected component containing the given point first,
% and finding the perimeter of the piece second

[Rows_i, Cols_i] = size(Image_given);
Enclosing = zeros(Rows_i+2, Cols_i+2);
Enclosing(2:Rows_i+1, 2:Cols_i+1) = Image_given;
Area = bwarea(Enclosing);
if Area < Min_area
Boundary = 0;
return;
end
Boundary = bwperim(Enclosing);
[Rows, Cols] = find(Boundary);
Boundary = [Rows'; Cols'];
Boundary = Boundary-ones(size(Boundary));

function Dense_pts = Fit_spline (Pts)

Xdata = Pts(1, :);
Ydata = Pts(2, :);

% making splines separately for X and Y, but with common parameter
Length = 0;
Param(1) = Length;
for i=1:length(Xdata)-1
Length = Length + norm(Pts(:, i+1) - Pts(:, i));
Param(i+1) = Length;
end

% sampling at a dense set of points
Gridpts = [min(Param):0.1:max(Param)];
Xspline = round(spline(Param, Xdata, Gridpts));
Yspline = round(spline(Param, Ydata, Gridpts));

% if not sufficiently dense, adjusting those
k = 0;  Dense_pts = zeros(2, 0);
for i=1:length(Xspline)-1
if max(abs(Xspline(i+1)-Xspline(i)), abs(Yspline(i+1)-Yspline(i))) > 1
for j=0:abs(Xspline(i+1)-Xspline(i))
k = k+1;
Dense_pts(:, k) = [Xspline(i) + j*sign(Xspline(i+1)-Xspline(i)); ...
Yspline(i)];
end
for j=0:abs(Yspline(i+1)-Yspline(i))
k = k+1;
Dense_pts(:, k) = [Xspline(i+1); ...
Yspline(i) + j*sign(Yspline(i+1)-Yspline(i))];
end
else
k = k+1;
Dense_pts(:, k) = [Xspline(i); Yspline(i)];
end
end

## 联系我们 