How to detect drops and trim them to png files?

I worked on webapp. I am stuck here in a problematic issue. I will try to explain what I am trying to do. here you see the first large image in which there are green figures. what I want to do is crop these shapes into different png files and make their background transparent, as an example, cropped images below a large one.

Main image the input

Cropped 1.

Cropped 2.

Cropped 3.

The first image will be uploaded by the user, and I want to crop to pieces, as shown in the example of cropped images above. This can be done using the GD php library or server-side software written in python or C #. but I donโ€™t know what this operation is called, so I donโ€™t know what Google needs to search for information. it has something to do with computer vision detecting droplets and cutting them into pieces, etc. Any keywords, links would be helpful.

thanks for the help

+4
source share
4 answers

Opencv provides a function called cv :: findContours to search for related components in an image. If it is always green or white, you want a cv :: split image in channels, use cv :: threshold on the blue or red channel (they will be white in the white areas and near black in the green area) with THRESH_BINARY_INV (because you want to extract dark areas ), then cv :: findContours to detect drops. Then you can calculate the bounding box with cv :: boundingRect , create a new image of this size and use the path you received as a mask to fill in the new image.

Note. These are links to C ++ documentation, but these functions should be displayed in python and C # shells - see http://www.emgu.com for the latter.

+4
source

A very easy way to do this is to use Flood Fill / Connected Component Labeling . Basically, it will just use a greedy algorithm, grouping any pixels that were the same or similar in color.

This is definitely not an ideal way to detect drops and will only be effective in limited situations. However, it is much easier to understand and code and may be enough for your purposes.

+5
source

I believe this Wikipedia article describes the problem very well: http://en.wikipedia.org/wiki/Blob_detection

Unable to remember ready-to-use solutions (-:

+1
source

It really depends on which images you will process.

As Brian mentioned, you can use Connected Component Labeling, which is usually applied to binary images, where the foreground is indicated by white pixels and the background by black pixels (or vice versa). The problem is how to convert the original image to binary. If all images are similar to your example, this is straightforward and can be done using a threshold value. OpenCV provides useful methods:

For more complex images, all bets are disabled.

+1
source

Source: https://habr.com/ru/post/1336806/


All Articles