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
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;
thisBB(1) = midx - 100;
thisBB(3) = thisBB(1) + 199;
midy = thisBB(2) + thisBB(4)/2;
thisBB(2) = midy - 100;
thisBB(4) = thisBB(2) + 199;
Best Answer