Cropping an image with coordinate values
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sterne_17
el 2 de En. de 2023
Comentada: Image Analyst
el 4 de En. de 2023
I have an image with 848*1102 pixels after edge detection, and I want to crop out a part of the image accurately, so I need to use the coordinate values of the top left and bottom right points. How do I get the coordinates of these two points and crop the image?
0 comentarios
Respuesta aceptada
Image Analyst
el 2 de En. de 2023
Editada: Image Analyst
el 2 de En. de 2023
Try this:
grayImage = imread('001.jpg');
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels == 3
grayImage = grayImage(:, :, 2);
end
subplot(2, 1, 1);
imshow(grayImage);
axis('on', 'image')
% Binarize
mask = grayImage > 128;
% Get rid of things touching the border.
mask = imclearborder(mask);
% Label the image
[LabeledImage, numBlobs] = bwlabel(mask);
% Eliminate the outermost blob, which will have a label of 1. Just keep blobs labeled 2 and up.
mask = ismember(LabeledImage, 2:numBlobs);
% Find the corners of the remaining blobs -- the bounding box.
[r, c] = find(mask);
row1 = min(r)
row2 = max(r)
col1 = min(c)
col2 = max(c)
% Do the cropping
mask = mask(row1:row2, col1:col2, :);
subplot(2, 1, 2);
imshow(mask);
axis('on', 'image');
6 comentarios
Image Analyst
el 4 de En. de 2023
Since it's a sphere, and the curved part won't move very much from image to image, I suggestion you just make up a template mask that you can multiply by your image to erase everything outside it. Just take the attached mask and set your gray scale image, or segmented binary image, outside it to zero.
grayImage(~mask) = 0;
That way nothing on the border or any of those spurious reflections will appear after masking.
Más respuestas (1)
KALYAN ACHARJYA
el 2 de En. de 2023
[rows,colm]=find(image==1);
Get the indices as rows & colm
3 comentarios
Ver también
Categorías
Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!