How to crop different size of plant seed automatically?
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/735539/image.png)
In the second picture, the total number of plant seeds is around 10.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/735544/image.png)
3rd, I find the boundary of the edge and at least I want to crop a few.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/735549/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/735554/image.png)
댓글 수: 0
답변 (1개)
prabhat kumar sharma
2024년 4월 4일
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!
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!