How to split a binary mask in square 1000x1000 and keep only ROI?

1 回表示 (過去 30 日間)
France
France 2019 年 10 月 22 日
コメント済み: Image Analyst 2019 年 10 月 23 日
Hello! I have got a binary mask (0 background and 1 inside the ROI) and I need to split it in square 1000x1000 and keep only square where there is ROI, e.g. where sum of pixel is more than 80% Many thanks in advance

回答 (1 件)

Image Analyst
Image Analyst 2019 年 10 月 22 日
Use indexing. For example
croppedImage = originalImage(row1:row2, column1:column2, :);
You need to figure out what row1, row2, column1, and column2 are. Should be easy.
Not sure of what your definition of ROI is. There are lots and lots of squares in the image that contain 80% of the number of pixels in the image.
  2 件のコメント
France
France 2019 年 10 月 23 日
Thanks for your reply. My binary mask comes from a nevus on a skin (you can image the shape). The mask has all 1 inside the ROI (white) and all 0 outside, in the background (black). So I need to crop the binary mask into square 1000x1000 and then keep the index only of the square in which there is ROI for more than 80%. I guess I need to crop the image first, look each square (maybe with a for cycle) and if the sum of each pixel in a square is >80%, I should keep the index correspondig to that square (ROI) otherwise not, because that is background....
Image Analyst
Image Analyst 2019 年 10 月 23 日
Fill, take largest blob, find centroid, crop.
mask = imfill(mask, 'holes');
mask = bwareafilt(mask, 1);
props = regionprops(mask, 'Centroid');
col1 = round(props.Centroid(1) - 500);
col2 = col1 + 499;
row1 = round(props.Centroid(2) - 500);
row2 = row1 + 499;
croppedImage = originalImage(row1 : row2, col1 : col2, :);
Or, if you want the blob to be 80%, do this
mask = imfill(mask, 'holes');
mask = bwareafilt(mask, 1);
props = regionprops(mask, 'Centroid');
width = sqrt(props.Area / 0.8);
halfWidth = width / 2;
col1 = round(props.Centroid(1) - halfWidth);
col2 = col1 + width - 1;
row1 = round(props.Centroid(2) - halfWidth);
row2 = row1 + width - 1;
croppedImage = originalImage(row1 : row2, col1 : col2, :);
It will probably not be 1000x1000 though.

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

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by