How to check neighbouring elements in a 2D array

I have a 2D array (~1000x1000) of intensity values that I would like to transform into an image to use as a mask for data processing in another program. I would like to mask out the dark lines and the corners:
What I am thinking is that for each element in the array, the neighbouring values (e.g. in a set radius) are checked for the proportion of zero values. If the proportion of zero values is above a set threshold, it should return a zero and otherwise it should return a one.
Happy to hear suggestions about other ways of going about this, and thank you in advance.

2 件のコメント

KSSV
KSSV 2023 年 6 月 19 日
To checl neighbouring elements read about knnsearch. What exactly you are epxecting? You want to make black lines inside the whitre region to white?
Oliver Lindsay
Oliver Lindsay 2023 年 6 月 19 日
Basically I would like the black regions (lines and corners) to be solid black, and the white regions to be solid white.
Here is an example of a type of output I'd be looking for, noting that it doesn't have the corners cut out.

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

 採用された回答

Matt J
Matt J 2023 年 6 月 19 日
編集済み: Matt J 2023 年 6 月 19 日

0 投票

load Image
BW=bwareaopen(~BW,100);
se=ones(7);
BW=medfilt2(BW,size(se));
BW=bwareaopen(BW,100);
BW=~bwareaopen(~BW,100);
BW=imclose(BW,se);
BW=conv2(BW,ones(5),'same')>0.5;
imshow(BW,[]); shg

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDisplay Image についてさらに検索

製品

リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by