How to crop different size of plant seed automatically?

1 visualización (últimos 30 días)
Ariunzaya Gantulga
Ariunzaya Gantulga el 11 de Sept. de 2021
Respondida: prabhat kumar sharma el 4 de Abr. de 2024
Hello everyone.
I have a microscope scanned seed image. I want to find the boundary of the edge seeds and then crop the boundary of the edge and save all the cropped seeds. What should I do? For example: first image is original image.
In the second picture, the total number of plant seeds is around 10.
3rd, I find the boundary of the edge and at least I want to crop a few.
How to crop as shown in last figure?

Respuestas (1)

prabhat kumar sharma
prabhat kumar sharma el 4 de Abr. de 2024
I understand that you have the image which is having all the blue bounding boxes and you are looking for a method to extract all the different bounding boxes as a seperate image.
To crop multiple bounding boxes from an image and save each crop as a separate image, you can follow the steps outlined below. This example assumes you have the coordinates of the bounding boxes in the format [x, y, width, height], where (x, y) are the coordinates of the top-left corner of the bounding box.
Here's a basic MATLAB script that demonstrates how to do this:
% Load the image
image = imread('path_to_your_image.jpg');
% Assuming you have 3 bounding boxes for demonstration
boundingBoxes = [
100, 50, 120, 150; % Box 1
250, 75, 100, 125; % Box 2
400, 100, 150, 200; % Box 3
];
% Number of bounding boxes
numBoxes = size(boundingBoxes, 1);
% Loop through each bounding box and crop the image
for i = 1:numBoxes
bbox = boundingBoxes(i, :);
x = bbox(1);
y = bbox(2);
width = bbox(3);
height = bbox(4);
% Crop the image based on the bounding box
croppedImage = imcrop(image, [x, y, width, height]);
% Save the cropped image
croppedImageFilename = sprintf('cropped_image_%d.jpg', i);
imwrite(croppedImage, croppedImageFilename);
end
I hope it helps!

Categorías

Más información sobre Images 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!

Translated by