n-dimensional-flood-fill | dimensional implementation of flood fill | Artificial Intelligence library
kandi X-RAY | n-dimensional-flood-fill Summary
kandi X-RAY | n-dimensional-flood-fill Summary
A non-recursive, n-dimensional implementation of flood fill.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of n-dimensional-flood-fill
n-dimensional-flood-fill Key Features
n-dimensional-flood-fill Examples and Code Snippets
Community Discussions
Trending Discussions on n-dimensional-flood-fill
QUESTION
I have a number of medical pictures presented on canvas, as an example below.
I’m trying to make a tool that allows you to select any area of the image with the tool in the form of an expandable circle, and fill in only that part of it that doesn't go beyond the outline in which the original click pixel was located. A filled outline is drawn on a separate canvas layer.
Now I use the most common iterative stack implementation of flood fill with variable tolerance (comparison function). You can familiarize yourself with it here. Everything doesn't work very well, especially in pictures where there are no strong contrast differences and in high-resolution images, everything else is pretty slow.
I had the idea to create a state container and look for whether the desired filled outline exists there and if so, then just replace the canvas pixel array (though, again, I will have to resort to some additional processing, the canvas pixel array contains 4 channel, while at the output of the algorithm only 1 is obtained and just replacing the content doesn't work, you need to replace each pixel with a pixel divided into 4 channels) instead of a slow flood fill each time. But this approach has one significant problem: memory consumption. As you might guess, a filled outline, especially of a decent resolution alone, can take up quite a lot of space, and their set becomes a real problem of memory consumption.
It was decided to store the finished contours in the form of polygons and extracting them from the container simply fill them with faster context fill. The algorithm used allows me to output a set of boundaries, but due to the features of the algorithm, this array is unordered and connecting the vertices in this order, we get only a partially filled outline (right picture). Is there a way to sort them in such a way that I could only connect them and get a closed path (the holes that are in the filled outline in the left picture shouldn't be a priori, so we don’t have to worry about them)?
Summing up, due to the not-so-best fill job, I think to use a different algorithm / implementation, but I don’t know which one. Here are some of my ideas:
Use a different implementation, for example, a line scanning method. As far as I know, here is one of the fastest and most effective implementations of the algorithm among open sources. Pros: possible efficiency and speed. Cons: I need to somehow convert the result to a polygon, rewrite the algorithm to javascript (probably emscripten, can do it well, but in any case I will have to rewrite a considerable part of the code).
Use a completely different approach.
a) I don’t know, but maybe the Canny detector can be useful for extracting the polygon. But as far as the use of the program is meant on the client side, it will be unprofitable to extract all the boundaries, it is necessary to figure out how to process only the necessary section, and not the entire picture.
b) Then, knowing the border, use any sufficiently fast fill algorithm that simply won't go beyond the boundaries found.
I'll be glad to know about some other ways, and even better to see ready-made implementations in javascript
UPD:
For a better understanding, the tool cursor and the expected result of the algorithm are presented below.
...ANSWER
Answered 2020-May-09 at 16:19Here is an example with opencv
Below should work or eventually use the fiddle link provided inside the code snippet
Of interest: approxPolyDP which may be sufficient for your needs (check Ramer-Douglas-Peucker algorithm)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install n-dimensional-flood-fill
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page