Extract horizontal and vertical lines from raster image

7 ビュー (過去 30 日間)
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 6 月 7 日
I am trying to extract horizantal and vertical bars seprately from following raster image.
I am using two combination of functions
First functions combination (parameters value may vary)
SE = strel('line',60,0);
% OR
SE = strel('rectangle',[1 70]);
s=imerode(Iraster,SE);
s=imdilate(s,SE);
Second functions combination
mask = imclearborder(Iraster);
props = regionprops(mask, 'Area');
allAreas = sort([props.Area])
mask = ~bwareaopen(~mask, 10000);
mask = imclose(mask, true(5));
mask = ~bwareaopen(~mask, 10000);
mask = bwareafilt(mask, 1);
barsH = medfilt2(mask, [1, 115]);
props = regionprops(barsH, 'Area', 'PixelList');
allAreas = sort([props.Area])
props = regionprops(barsH, 'Area', 'PixelList');
allAreas = sort([props.Area])
The outcomes are not satisfactory, as outputs are not smooth like in original image.
Are there any other functions that can be helpful ?. I raster.mat is enclosed.

採用された回答

yanqi liu
yanqi liu 2022 年 6 月 7 日
yes,sir,may be use open and close operation,such as
load Iraster.mat
bw = im2bw(Iraster);
bw2 = imclose(bw, strel('line', 1e2, 0));
bw3 = imopen(bw2, strel('line', 50, 90));
bw3 = imclose(bw3, strel('line', 2e3, 90));
bw3 = imdilate(bw3, strel('disk', 9));
bw3 = logical(bw3.*bw2);
bw4 = logical(~bw3.*bw2);
bw4 = imclose(bw4, strel('line', 3e2, 0));
bw4 = bwareaopen(bw4, 1e3);
bw4 = logical(bw4.*bw2);
figure; imshow(bw2);
figure; imshow(bw3);
figure; imshow(bw4);
  3 件のコメント
Image Analyst
Image Analyst 2022 年 6 月 8 日
編集済み: Image Analyst 2022 年 6 月 8 日
1e2 = 1 * 10 ^ 2 = 100.
1e3 = 1 * 10 ^ 3 = 1000.
format long g
1e2
ans =
100
1e3
ans =
1000
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 6 月 10 日
@Image Analyst thank you for clarifying this.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by