How can I calculated centroid contour distance in image at every 10 degree?
古いコメントを表示
I I have done many experiments, but I have not been able to determine the angle in the image, I want to get the vertices only at every 10 degrees, but in my experiments, I get the vertices on each pixel contained in the image? please help me solve this problem :). Here is my code
clc;
close all;
clear all;
fontSize = 10;
image_folder = 'D:\Mangrove Classification\Data Training';
filenames = dir(fullfile(image_folder, '*.png'));
total_images = numel(filenames);
for n = 1:total_images
full_name= fullfile(image_folder, filenames(n).name);
I = imread(full_name);
I = imresize(I,0.2);
M = I(:,:,1) < 168;
% Fill holes
M = imfill(M, 'holes');
% Take largest blob only.
M = bwareafilt(M, 1);
subplot (1,2,1);
imshow(M);
[labeledImage numberOfBlobs] = bwlabel(M, 8);
blobMeasurements = regionprops(labeledImage, 'Centroid', 'Orientation');
xCenter = blobMeasurements(1).Centroid(1);
yCenter = blobMeasurements(1).Centroid(2);
subplot(1,2,2);
imshow(I);
axis on;
hold on;
% Plot the centroid.
plot(xCenter, yCenter, 'b+', 'MarkerSize', 10, 'LineWidth', 3);
boundaries = bwboundaries(M);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
for k = 1 : length(boundaries)
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'b', 'LineWidth', 2);
numberOfBoundaryPoints = length(thisBoundary);
angle = 0: 10 : 360;
for a = 1 : length(angle)
xb = thisBoundary(a,2);
yb = thisBoundary(a,1);
angles(a) = atand((yb-yCenter) / (xb-xCenter));
distances(a) = sqrt((xb-xCenter).^2+(yb-yCenter).^2);
end
end
save('Latih.mat','angles','distances');
end
4 件のコメント
darova
2019 年 12 月 13 日
The code doesn't work
Muhammad Andi Yusran
2019 年 12 月 13 日
darova
2019 年 12 月 13 日
I mean we don't have your data to try your code. CAn your attach?
Muhammad Andi Yusran
2019 年 12 月 13 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

