Should this simple Marvin example take several minutes to execute?

88 views
Skip to first unread message

Zach Buckner

unread,
Oct 22, 2018, 9:31:50 PM10/22/18
to Marvin Project
I'm trying to segment black and white images, to identify rectangular regions that contain roughly contiguous "blobs" of pixels.  I've tried using this block of code which uses the Marvin image processing framework, which does the operation perfectly, it's just too slow.  For a single 2000x2000 black and white image, the solution takes a couple of minutes to run.   Does this sound normal?  I would have expected the operation to complete in milliseconds, but nearly every operation (each line in the script) takes many seconds to run.  

Any help will be greatly appreciated.

Best,
Zach

Gabriel Ambrósio Archanjo

unread,
Oct 22, 2018, 10:39:16 PM10/22/18
to Marvin Project
Hi Zach,


Since this code uses flood fill segmentation, the necessary time to process an image can increase exponentially with the resolution.

However, do you really need to process the image in the original resolution? It only makes sense to process an image in 2000x2000 if you can't keep the image features in a lower resolution. 

This same robocup example was implemented in javascript (interpreted script language with a lower performance). In this case the image was scaled down to 180 pixels width and the result is the same:

Try, for instance, to process your image in 400 pixels width. After loading the image, scale it down as follows:

scale(image.clone(), image,400);

After obtaining the segments or blobs you can scale them up to the original resolution (2000x2000) simply multiplying the coordinates by 5. (400x400 * 5 = 2000x2000)

Zach Buckner

unread,
Oct 22, 2018, 11:33:01 PM10/22/18
to Marvin Project
Thanks for the quick response, Gabriel.  I noticed that the algorithm was quite a bit faster if I scaled the image down, but unfortunately my input images have smaller features/segments that are getting lost when I scale down before segmentation. 

Is there any hope of improving performance if I were to attempt to learn how the flood fill segmentation algorithm works and attempted to optimize it?  For example, is there any performance gain possible by modifying the floodfill plugin to directly manipulate binary images (vs Rgb)?

Best,
Zach
Reply all
Reply to author
Forward
0 new messages