# Create vectors that allow to subdivide the pixels of an image

1 visualización (últimos 30 días)
Alejandro Fernández el 9 de Jul. de 2021
Comentada: Alejandro Fernández el 10 de Jul. de 2021
Hello, I was wondering if someone could tell me how I can subdivide an image, for example img, so that I can store in a vector the positions of the rows and in another vector the columns (which logically would not be integers) to divide each pixel in 5 parts.
img = rand(10,20);
figure, imshow(img,'InitialMagnification','fit');
That is, what I would like is to be able to build a grid that follows the basis of what the poly2mask function does but with all the pixels:
Thank yo so much
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Matt J el 9 de Jul. de 2021
Editada: Matt J el 9 de Jul. de 2021
[m,n]=size(img);
y=linspace(0,m,5*m+1).'+0.1; y(end)=[];
x=linspace(0,n,5*n+1).'+0.1; x(end)=[];
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Matt J el 10 de Jul. de 2021
Editada: Matt J el 10 de Jul. de 2021
I don't see anything wrong, other than that the XData,YData that you've chosen for the image are oddly shifted,
img = rand(10,20);
[m,n]=size(img);
y=linspace(0,m,5*m+1).'+0.1; y(end)=[];
x=linspace(0,n,5*n+1).'+0.1; x(end)=[];
[X,Y] = meshgrid(x,y);
figure, imshow(img,'InitialMagnification','fit');
hold on
plot(X,Y,'.')
himg=findobj(gca,'Type','image');
himg.XData=(1:n)-0.5;
himg.YData=(1:m)-0.5;
axis([0,n,0,m])
Alejandro Fernández el 10 de Jul. de 2021
Ok! Thank you so much for your help!

Iniciar sesión para comentar.

### Categorías

Más información sobre Image Preview and Device Configuration en Help Center y File Exchange.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by