我试图找到一种方法在 Matlab 中围绕图像的一部分绘制一个框并找到该图像的质心。理想情况下,我希望“新”部分显示在我的原始图像旁边,然后我可以到那个“新”图像的质心。
这是我的代码:
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
A = imread('PET_MRI_Brain_Tumor.jpg');
Z = imshow(A)
Ibw = im2bw(A);
Ibw = imfill(Ibw,'holes');
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
imshow(Z); hold on;
for x = 1: numel(stat)
plot(stat(x).Centroid(1),stat(x).Centroid(2),'bx');
end
e = imellipse(gca,[55 10 120 120])
BW = createMask(e,Z)
这是我试图在上面放置蒙版并找到该部分的质心的图像。