Effacer les filtres
Effacer les filtres

How to crop different size of plant seed automatically?

2 vues (au cours des 30 derniers jours)
Ariunzaya Gantulga
Ariunzaya Gantulga le 11 Sep 2021
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?

Réponses (1)

prabhat kumar sharma
prabhat kumar sharma le 4 Avr 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!

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by