Auto cropping of pollen
3 次查看(过去 30 天)
显示 更早的评论
Ι want ot do the following:
I have this image and i want to create ROI of a pollen automatically.If i imcrop for example a small region with ,let say 5 pollens, i want to take 5 cropped images
of the pollens ,with the pollens centered and specific dimensions of the ROI.For example this image
Summarizing :
i imcrop and i get as many cropped images as the pollens are included inside the imcropped
image.How can i do it???
0 个评论
采纳的回答
Image Analyst
2019-1-19
编辑:Image Analyst
2019-1-19
First of all, take a black shot with no pollen in there, and divide your image by that blank shot to do background correction. I'm attaching a demo.
After that, you can do thresholding and cropping like I do in my Image Processing Tutorial: My File Exchange
You might want to convert your image to a binary image using the Color Thresholder on the Apps tab of the tool ribbon. Use the Export button to export the function to do the binarization. Basically to crop each, you'd do
props = regionprops(binaryImage, 'BoundingBox');
figure % Bring up new figure.
spRows = ceil(sqrt(length(props)));
for k = 1 : length(props)
thisBB = props(k).BoundingBox;
subImage = imcrop(originalImage, thisBB);
subplot(spRows, spRows, k);
imshow(subImage);
end
If you want a specific width and margin to your bounding boxes, then take thisBB and modify it. Like, to make it 50 pixels wider and 75 pixels taller:
thisBB(1) = thisBB(1) - 50;
thisBB(3) = thisBB(3) + 100;
thisBB(2) = thisBB(2) - 75;
thisBB(4) = thisBB(4) + 150;
Or, to make it always 200 pixels wide and tall, do this:
midx = thisBB(1) + thisBB(3)/2; % Right side plus half the width.
thisBB(1) = midx - 100;
thisBB(3) = thisBB(1) + 199;
midy = thisBB(2) + thisBB(4)/2;
thisBB(2) = midy - 100;
thisBB(4) = thisBB(2) + 199;
3 个评论
Image Analyst
2019-1-20
It saves every image, however since you forgot to change the name, they all get saved to the same filename. Why did you not create a new filtename with sprintf()? Like
filename = sprintf('Grain #%d.png', k);
imwrite(subImage, filename);
If you still get a round spot instead of a pollen grain, attach your image, and code where you background corrected, binarized, cropped, and saved the image.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!