【问题标题】:Extracting masked regions in an image提取图像中的蒙版区域
【发布时间】:2020-02-23 13:23:33
【问题描述】:

所以,我一直致力于在 Matlab 中进行车牌检测。我已经生成了所需的蒙版并将其与原始图像融合。现在,我只想提取被遮罩的区域,但无法找到一种方法来做到这一点。任何帮助将不胜感激。

这是我到目前为止编写的代码。

Im = imread("RPImage.jpg");
I = rgb2gray(Im);
I = medfilt2(I);
J = histeq(I);

%imshow(J)

[~,threshold] = edge(I,'sobel');
fudgeFactor = 0.5;
BWs = edge(I,'sobel',threshold * fudgeFactor);
%imshow(BWs)

BWs = bwareaopen(BWs, 8);
%imshow(BWs)

BWfill = imfill(BWs,'holes');
%imshow(BWfill)

mask = bwareaopen(BWfill, 1000);
%imshow(mask)

seD = strel('diamond',1);
BWfinal = imerode(mask,seD);
BWfinal = imerode(BWfinal,seD);
%imshow(BWfinal)
%title('Segmented Image');

imshow(labeloverlay(Im,BWfinal))
title('Mask Over Original Image')

这是输出:

【问题讨论】:

    标签: matlab image-processing object-detection


    【解决方案1】:
    rowvec = sum(BWfinal);
    colvec = sum(BWfinal, 2);
    
    first_row_id = find(colvec > 0, 1);
    last_row_id = find(colvec > 0, 1, 'last');
    
    first_col_id = find(rowvec > 0, 1);
    last_col_id = find(rowvec > 0, 1, 'last');
    
    rows = last_row_id - first_row_id + 1;
    cols = last_col_id - first_col_id + 1;
    
    roi = I(first_row_id:last_row_id, first_col_id:last_col_id);
    

    【讨论】:

    • 谢谢。事实证明,这可以通过一种非常简单、合乎逻辑的方法来完成。
    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多