On Thu, Nov 26, 2020 at 12:47:12PM +0100, Emanuel Berg wrote: > tomas wrote: > > >> Well, in computing, the details are everything. > > > > Yes, that's it -- and they are usually left... to the reader :) > > > > Why should I deprive you of your fun? > > > > Actually it's that my stack is too high: I just wanted to help > > you avoid barking up too many wrong trees; in this long thread > > I've already seen you & Andrey trying to develop (erroneous) > > variants of flood fill. If you have fun in it, I won't spoil > > that any longer. > > OK, but one step at a time then! > > How do you/what do you use to do this > > for pixel (x y) in image; do > if (pixel.color == BLACK) { pixel.color = GREEN } > done > > (made up syntax)
That will strongly depend on what tool/environment you use. And what BLACK actually means to you. Is it rgb(0,0,0), or does rgb(1,3,2) [I'm assuming colour values go between 0..255] also count as black? If it's the Magick suite we are talking about, try to make this experiment: - download this little guy over there [1] - do convert Western_Yellow_Robin_-_10486947383.jpg -fuzz 10% -fill black -opaque "#a0b0e0" robin.jpg - watch the results (now in robin.jpg) - play with different values of -fuzz How did I arrive at this '#a0b0e0'? Well, I took some point in the sky and looked at its colour. Hint: changing "-opaque <foo>" to "+opaque <foo>" will invert the effect, i.e. colours /other/ than <foo> (whithin the fuzz margin) will be overpainted with -fill. This might be more useful in your use case. In the end, you'll probably have to do a couple of steps [0]: - paint every colour in your image /not equal/ to your loop's colour (let's assume light grey, #d3d3d3: you /know/ which is your loop's colour, dont you?) in some othe colour, say black. If you know your loop's precise colour, you won't need a fuzz here. - flood fill (yes, here's where flood fill enters the -uh- picture) your loop's inner hole (you have some coords of your loop's inner hole, don't you) with some /third/ colour, say white. - use that image, stating white as your non-opaque colour to set your original's image's alpha channel [2] (i.e. you use your transformed image from step 2 as a mask or "cookie cutter" to cut out your region of interest). You'll need some experimenting to get it right. But you'll need some experimenting anyway to get an idea of what are the aspects of your problem, and of when it is a meaningful problem and when it is ill-posed. Ill-posed in the sense of: Where does this "gray loop" come from? Have you (electronically) painted it by hand? Then you might consider cutting the loop and learning about your tool's selection options. Does this loop come from a "photo"? Then its colour might not be as uniform as you would wish (your perception does tricks on you: you know that, don't you? The loop looks to you as a "perfect gray loop with no gaps, and nobody else in the image has this gray colour", but that's the result of some magic and wonderful image processing in your visual cortex). And so on. The only way of getting a feeling for such things is playing around. So perhaps some quality time with the Gimp or Krita is the better approach for you. Magick is great once you /know/ what you are doing to script a process. Cheers [0] Variations are possible depending of whether you want the gray loop itself to be part of the final image or not. You might be able to skip intermediate steps if there were a "flood fill everything /different/ from this-and-this colour, but to my knowledge there isn't; you might try to hack Magick's source, though). [1] https://upload.wikimedia.org/wikipedia/commons/4/4b/Western_Yellow_Robin_-_10486947383.jpg [2] https://imagemagick.org/Usage/compose/#copyopacity - t
signature.asc
Description: Digital signature