Using bwpropfilt after imrotate
2 views (last 30 days)
I have a code that detects objects from an image using bwconncomp, this function detects more then 4000 objects in my original image.
I realized that i need to rotate the image in order for the object detection algorithm to work better.
When I use imrotate before the function bwconncomp it recognizes 380 objects (much less then the original):
-> differences marked in red
What do I need to add in order that i will be able to detect the same number of objects in both images (the original and the rotated)?.
I also realized that when im using the imrotate the size of the image is changing so im using it with crop:
And then the size does not change, and when I use imshow the image looks the same.
Any help will be highly appreciated!!
Matt J on 31 Jul 2022
Edited: Matt J on 31 Jul 2022
The reason, I suspect, that the number of objects seems to decrease when you imrotate is that you have several objects that are very close together in the original image - less than 2 pixels apart. When you imrotate, the interpolation operations done by the rotation introduce new non-zero pixels that bridge the pixel-wide gaps between objects, thereby fusing what were separate objects together..
You need to assess whether these narrowly separated objects are truly supposed to be separate. If there is a minimum distance that is supposed to exist between distinct objects, then you can use imclose to seal false gaps in the original image. bwpropfilt or bwareafilt might help also to get rid of objects in the original image that are just a few pixels in size.