How to split a binary mask in square 1000x1000 and keep only ROI?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Image Analyst
il 22 Ott 2019
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 Commenti
Image Analyst
il 23 Ott 2019
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.
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!