@Image Analyst please help me.
How to get the coordinate of cropped rectangular image?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aminah Zhulaika
el 22 de Jun. de 2021
Comentada: Aminah Zhulaika
el 23 de Jun. de 2021
I cropped the image as a box. Then i need to use the coordinate of the cropped image for another task. How to get that coordinate? I am using this code btw from ImageAnalyst.
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
% Find the coordinates of the box.
xCoords = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)];
yCoords = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)];
x1 = round(xCoords(1));
x2 = round(xCoords(2));
y1 = round(yCoords(5));
y2 = round(yCoords(3));
hold on
axis manual
plot(xCoords, yCoords, 'b-'); % redraw in dataspace units
Respuesta aceptada
Image Analyst
el 23 de Jun. de 2021
The coordinates are x1,x2,y1, and y2. So to crop:
croppedImage = originalImage(y1:y2, x1:x2, :);
5 comentarios
Image Analyst
el 23 de Jun. de 2021
imcrop() uses [xLeft, yTop, xWidth, yHeight] format, NOT (y1, y2, x1, x2) like you'd do if you were indexing. so
r = [x1, y1, (x2-x1), (y2-y1)];
croppedImage = imcrop(rgbImage, r);
Más respuestas (1)
Walter Roberson
el 23 de Jun. de 2021
I have manually cropped the area in image 1
Then I predict that the issue is that you do not know what coordinates you manually outlined. The way to deal with that is to ask for an additional output from imcrop()
[J1, rect] = imcrop(I1);
J2 = imcrop(I2, rect);
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!