How to split a binary mask in square 1000x1000 and keep only ROI?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!