# Scale a mask in an image

22 visualizaciones (últimos 30 días)
Carine el 26 de Nov. de 2015
Respondida: Carine el 20 de En. de 2016
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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Carine el 20 de En. de 2016
What I wanted in fact was a disk around the "ellipse like blob". So, at the end, what I've done, using Imresize, is designing two such shapes (ellipse like bigger than the original one) and combining them:
agr = 0.03;
Ims1 = Im(floor(1-agr+agr*centre(k,2)):ceil(rows*1-agr)+agr*centre(k,2)),...
floor(1-agr+agr*centre(k,1)):ceil(columns*(1-agr)+agr*centre(k,1)));
Ims1 = imresize(Ims1,[rows columns]);
agr = 0.25;
Ims2 = Im(floor(1-agr+agr*centre(k,2)):ceil(rows*(1-agr)+agr*centre(k,2)),...
floor(1-agr+agr*centre(k,1)):ceil(columns*(1-agr)+agr*centre(k,1)));
Ims2 = imresize(Ims2,[rows columns]);
where Im is the image with the original blob, "centre" is the centre of the original blob and [rows,colums] the size of the first image.
The result is in the image included.
Cheers
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Más respuestas (2)

Stefan Karlsson el 26 de Dic. de 2015
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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Region and Image Properties en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by