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!