簡體   English   中英

在二進制圖像中標記對象MATLAB

[英]Labeling object in a binary image MATLAB

我正在嘗試使用MATLAB在二進制圖像中標記白色對象。 基本上,我的目標是在空中地圖圖像中檢測水體,然后將cimage轉換為二進制圖像,然后標記水體。 這是檢測到物體並轉換為二進制后的輸出示例。 現在如何在白色物體周圍創建一個創建矩形並用文本標記它們(使用連接的組件)? 謝謝!

在此處輸入圖片說明

嘗試這個 -

%%// Read in the image file
img = im2bw(imread(FILE));

%%// Get bounding box stats
stats = regionprops(bwlabel(img),'Area','Centroid','Perimeter','BoundingBox');
Boxes=cat(1,stats.BoundingBox);

%%// Placeholder to store the final result
maskm = false(size(img,1),size(img,2));

for k1 = 1:size(Boxes,1)

    %%// Initialize a mask representing each bounding box
    mask1 = false(size(img,1),size(img,2));

    %%// Get the coordinates of the boxes
    starty = round(Boxes(k1,1));
    stopy = starty+round(Boxes(k1,3))-1;
    startx = round(Boxes(k1,2));
    stopx = startx+round(Boxes(k1,4))-1;

    %%// Finaly create the mask
    mask1(startx:stopx,starty:stopy) = true;
    maskm = maskm + imdilate(edge(mask1,'sobel'),strel('disk',2));
end

%%// Get the boxes around the original blobs
maskm = maskm + img;
figure,imshow(maskm);

產量

在此處輸入圖片說明

調查有關如何標記框的文本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM