Scale a mask in an image
Mostrar comentarios más antiguos
Dear all,
I have a mask which is convex (ellipse like although not a real ellipse). I want to scale it to obtain a mask bigger with the same shape and centered at the same place. Would anybody know how to do that?
I attach an example of the mask.

Cheers.
Respuesta aceptada
Más respuestas (2)
Stefan Karlsson
el 26 de Dic. de 2015
1 voto
use imresize. If you use it with interpolation 'nearest', you have your functionality in a single line. If you use another interpolation method (like bilinear for example) you will need to transform the result back to binary through thresholding. It will generate pixel values inbetween 0 and 1.
Image Analyst
el 26 de Dic. de 2015
Depends on what you mean by "the same shape". Does the image have to be the same size and shape? If you want approximately the same shape of the white blob, but are willing to have a larger image, then you can use imresize() like Stefan suggested.
If you want the same size image but just have the white blob larger, then you could use imdilate():
newMask = imdilate(mask, true(11)); % Whatever number gets you the size you want.
However this will round out the shape (smooth it) the larger it gets. If you want a larger white blob but the same size image, you can do it in two ways.
One is to call imresize with the nearest option and then crop the image. You'll have to figure out the rows and columns to crop it at.
The second way is to use bwboundaries() to get the x and y coordinates of the perimeter, and use regionprops() to get the centroid. Then calculate the distance of each point from the centroid and extrapolate that outwards by some scale factor. Now you have a new set of expanded x,y coordinates and you can use poly2mask() to turn them into a binary image. This should be perhaps the most accurate way to retain the exact shape.
Categorías
Más información sobre Region and Image Properties en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!