Auto cropping of pollen
조회 수: 3 (최근 30일)
이전 댓글 표시
DIMITRIOS THEODOROPOULOS
2019년 1월 19일
댓글: DIMITRIOS THEODOROPOULOS
2019년 1월 20일
Ι 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!