How to crop square of size 100 X 100 around the centroid of an image?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Manjiree Waikar
el 9 de Sept. de 2017
Comentada: Manjiree Waikar
el 9 de Sept. de 2017
I have a binary image with centroid and I want to crop 100 X 100 image patch from the centroid of the image. I tried using imrect command and imcrop command. But it does not give automatic extraction of that patch instead I need to drag and place the square. Please help with MATLAB code for this.
Respuesta aceptada
Jose Marques
el 9 de Sept. de 2017
Change x_cent and y_cent for your centroids; change the name of images variables
x_cent = 120;
y_cent = 150;
size_of_cropped_img = 100;
centroide = [x_cent y_cent];
I = imread('circuit.tif');
imshow(I);
%I2 = imcrop(I,rect) crops the image I. rect is a four-element position vector of the
%form [xmin ymin width height] that specifies the size and position of the crop rectangle.
%imcrop returns the cropped image, I2.
xmin = x_cent-size_of_cropped_img/2;
ymin = y_cent-size_of_cropped_img/2;
I2 = imcrop(I,[xmin ymin size_of_cropped_img size_of_cropped_img]);
figure();
imshow(I2)
6 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!