我正在尝试使用手动 ROI 选择来追踪对象的边界,并以灰度将轮廓绘制回原始图像上。我注意到轮廓相对于原始对象位置发生了变化。为什么?我的代码中遗漏了什么吗?
代码:
close all;
clear all;
clc;
I = imread('pillsetc.png');
figure('Name','pillsetc');
imshow(I)
x1 = 50;
y1 = 200
Iroi = imcrop(I,[x1,y1,400,150]);
GrayRoi = rgb2gray(Iroi);
figure('Name','pillsetcGrayCrop');
imshow(GrayRoi);
BWRoi = imbinarize(GrayRoi);
BWRoi = bwareaopen(BWRoi, 10);
BWRoi = imfill(BWRoi,'holes');
[B,L] = bwboundaries(BWRoi,'noholes');
stat = regionprops(L, 'Centroid');
figure('Name','pillsetcCropBoundaries');
imshow(rgb2gray(I));
hold on;
for k = 1 :numel(stat)
b = B{k};
c = stat(k).Centroid;
plot(b(:,2)+x1, b(:,1)+y1,'r');
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用下面的代码计算两个对象的外切半径和内切半径。我使用了这个脚本中的 inscribedRadius 参数 和外接半径我使用了这个函数
我不明白为什么我得到内切半径大于外切半径的盒子形状。知道出了什么问题吗?以及如何修复它?
代码:
clc;
clear;
RGB = imcomplement(imread('https://i.stack.imgur.com/8WLAt.jpg'));
I = rgb2gray(RGB);
bw = imbinarize(I);
bw = imfill(bw,'holes');
imshow(bw)
hold on;
[B,L] = bwboundaries(bw,'noholes');
stats = regionprops(L,'Centroid','MajorAxisLength');
for i = 1 : numel(stats)
b = B{i};
c = stats(i).Centroid;
y = b(:,1);
x = b(:,2);
plot( b(:,2),b(:,1),'Color','red','linewidth',2);
text(c(1),c(2),num2str(i),'Color','red');
xMin = min(x);
xMax = max(x);
yMin = min(y);
yMax = max(y);
scalingFactor = 1000 / min([xMax-xMin, yMax-yMin]);
x2s = (x - xMin) * scalingFactor + …Run Code Online (Sandbox Code Playgroud)