Re: color border in image, drop everything outside of it

2020-11-26 Thread Emanuel Berg
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)

?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-26 Thread Emanuel Berg
tomas wrote:

> I'm not going to fill in the details.

Well, in computing, the details are everything.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-26 Thread tomas
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 " to "+opaque " will invert
the effect, i.e. colours /other/ than  (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


Re: color border in image, drop everything outside of it

2020-11-26 Thread tomas
On Thu, Nov 26, 2020 at 12:24:40PM +0100, Emanuel Berg wrote:
> tomas wrote:
> 
> > I'm not going to fill in the details.
> 
> 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.

Cheers
 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-26 Thread tomas
On Thu, Nov 26, 2020 at 01:22:51AM +0100, Emanuel Berg wrote:
> tomas wrote:
> 
> >> BTW maybe the AI people already have a true and tested
> >> algorithm for this problem?
> >
> > I repeat myself. It is a variant of flood fill. AI not needed.
> > Classical raster computer graphics stuff.
> 
> Well, AI or not, I remember the old graphics program (e.g.,
> MacPaint) did this all the time. Filled inner and outer regions.
> But these regions were uniform, that's the difference...

You don't listen. You don't follow the links. This way, we'll
run in loops (pun intended) for the rests of our lives (luckily
mine is about 3/4 done).

If the regions were uniform, we are talking straight, classical
flood fill, something you would have found out yourself by a
short look at the Wikipedia article I referenced in my last
mail.

The non-uniform case is why I was talking about a "variation"
of the flood fill algorithm. When programming it yourself,
you'd to tweak your comparison operator appropriately. When
doing it as a ImageMagick pipeline, you'd have to make "your"
region uniform first, à la

  convert  -fuzz 10% -fill white -opaque  


or something. Then flood fill. Then use that as mask for your
original.

I'm not going to fill in the details. Gotta cook now.

Cheers
 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-25 Thread Emanuel Berg
tomas wrote:

>> BTW maybe the AI people already have a true and tested
>> algorithm for this problem?
>
> I repeat myself. It is a variant of flood fill. AI not needed.
> Classical raster computer graphics stuff.

Well, AI or not, I remember the old graphics program (e.g.,
MacPaint) did this all the time. Filled inner and outer regions.
But these regions were uniform, that's the difference...

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-24 Thread Emanuel Berg
David Wright wrote:

> Original Scanned
>
> d→
> d→
> ss
> skkksskkks
> skkksskkks
> skkkskkksskkkskkks
> skkksskksskkksskks
> skkksdsssskkksdsss
> skkksskkks
> skkksskkks
> skkksskkks
> skkksskkks
> skkksskkks
> dskkksddd→skkks←←←
> ddskkksdd→→skkks←←
> dddskkksd→→→skkks←
> ddsks→→sks
> dskkksddd→skkks←←←
> sksddsks←←
> d←
> d→
> d→
>
> Achieved Desired
>
> ..
> ..
> ss
> skkksskkks
> skkksskkks
> skkkskkksskkkskkks
> skkksskksskkksskks
> skkksdsssskkks.sss
> skkksskkks
> skkksskkks
> skkksskkks
> skkksskkks
> skkksskkks
> .skkks....skkks...
> ..skkks....skkks..
> ...skkks....skkks.
> ..sks..sks
> .skkks....skkks...
> sks..sks..
> ..
> ..
> ..

OK, nice work, good point!

Well, you have to extent the algorithm so that when it hits a dead
end, it doesn't stop, instead it tries the other directions.

Or maybe do it like this: just rush forward until you hit
something. When you do, proceed around it as tightly as possible
until you reach the original position!

BTW maybe the AI people already have a true and tested algorithm
for this problem?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-24 Thread tomas
On Tue, Nov 24, 2020 at 10:39:08PM +0100, Emanuel Berg wrote:

[...]

> BTW maybe the AI people already have a true and tested algorithm
> for this problem?

I repeat myself. It is a variant of flood fill [1]. AI not needed.
Classical raster computer graphics stuff.

Cheers

[1] https://en.wikipedia.org/wiki/Flood_fill

 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-24 Thread David Wright
On Mon 23 Nov 2020 at 06:23:50 (+0100), Emanuel Berg wrote:
> > I don't understand what you mean by "sensible" data.
> > Your example
> >
> >   .
> >   ...sss...
> >   ..skkks..
> >   ..s..
> >   ss...
> >
> > is a completely convex blob. Are we to understand that as
> > a constraint? Or are re-entrant shaped loops allowed? What sort
> > of re-entrants?
> 
> I have described the intention using everyday language.
> 
> Then I described the algorithm that would accomplish this.
> 
> Finally, I provided this ascii art example.
> 
> If that still isn't enough, well, you know what they say, it ain't
> worth it explaining to someone who doesn't understand.

Fair enough, but I thought you were worth explaining it to, so here
goes with some ascii art. I started with a larger image than yours at
https://lists.debian.org/debian-user/2020/11/msg00496.html
but using the same notation, and I carried out your algorithm at
https://lists.debian.org/debian-user/2020/11/msg00494.html
but showing my working by leaving arrows as the scan passed.

The first pass is simple, with 'd' turning into →. In the second
pass, I've only shown ↓ where there was still a 'd' to be dropped,
so there aren't any ↓ marks down the lefthand side or along the
top, as those have already been dropped. (If you're unconvinced,
a 'trampling' version is attached.)

Similarly for the third and fourth passes. This last scan does
nothing of course because it either scans up over points already
dropped, or hits an 's' and stops.

As you can see, there are several 'd's left at the end of all four
scans, which your algorithm misses because the 's' loop stopped
the scan from reaching them.

Original Scanned

d→
d→
ss
skkksskkks
skkksskkks
skkkskkksskkkskkks
skkksskksskkksskks
skkksdsssskkksdsss
skkksskkks
skkksskkks
skkksskkks
skkksskkks
skkksskkks
dskkksddd→skkks←←←
ddskkksdd→→skkks←←
dddskkksd→→→skkks←
ddsks→→sks
dskkksddd→skkks←←←
sksddsks←←
d←
d→
d→

Achieved Desired

..
..
ss
skkksskkks
skkksskkks
skkkskkksskkkskkks
skkksskksskkksskks
skkksdsssskkks.sss
skkksskkks
skkksskkks
skkksskkks
skkksskkks
skkksskkks
.skkks....skkks...
..skkks....skkks..
...skkks....skkks.
..sks..sks
.skkks....skkks...
sks..sks..
..
..
..

Cheers,
David.
Trampled

←
←
s
skkks
skkks
skkkskkks
skkksskks
skkksdsss
skkks←←←↑
skkks←←←↑
skkks←←←↑
skkks←←←↑
skkks←←←↑
→skkks←←↑
→→skkks←↑
→→→skkks↑
→→sks←←←↑
→skkks←←↑
sks←↑
↑
↑
↑


Re: color border in image, drop everything outside of it

2020-11-23 Thread Emanuel Berg
> I don't understand what you mean by "sensible" data.
> Your example
>
>   .
>   ...sss...
>   ..skkks..
>   ..s..
>   ss...
>
> is a completely convex blob. Are we to understand that as
> a constraint? Or are re-entrant shaped loops allowed? What sort
> of re-entrants?

I have described the intention using everyday language.

Then I described the algorithm that would accomplish this.

Finally, I provided this ascii art example.

If that still isn't enough, well, you know what they say, it ain't
worth it explaining to someone who doesn't understand.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-22 Thread David Wright
On Sun 22 Nov 2020 at 05:14:25 (+0100), Emanuel Berg wrote:
> David Wright wrote:
> 
> >> Encirclement!
> >
> > How does that work with figures like Ω or ω?
> 
> Well, if the input data doesn't make sense, why worry about the
> output data?

I don't understand what you mean by "sensible" data. Your example

  .
  ...sss...
  ..skkks..
  ..s..
  ss...

is a completely convex blob. Are we to understand that as a
constraint? Or are re-entrant shaped loops allowed? What sort
of re-entrants?

I was just pointing out that while your super-easy example works
in a really simple manner, many common shapes, like the attached,
just won't work with that algorithm. Treating each of your scans
as light rays, there are shadow areas that are never scanned,
like the armpits.

Cheers,
David.


Re: color border in image, drop everything outside of it

2020-11-22 Thread Emanuel Berg
tomas wrote:

> You are (nearly) describing flood fill. Except that the operator
> is ≠ instead of = or, perhaps you have two phases, one with "≠
> grey" and then one with "= grey" to also eliminate the doodle.
>
> I really, strongly suggest you play around with ImageMagick and
> "connected component labeling". Here[1]'s the ref, in case it
> got lost in the intratubes.

That must be something else? Seems much more complicated. I don't
understand the commands and they seem to do something else.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-22 Thread tomas
On Sun, Nov 22, 2020 at 03:11:21AM +0100, Emanuel Berg wrote:

[...]

> start at (0, 0) - this is the top-left pixel, as you know - is
> this color gray? answer: no. go to (1, 0) etc until you get to
> a grey pixel. at that point, discard all pixels until then.
> and don't look any further to the right on that row!
> 
> do this for all rows from left to right, top to bottom.
> 
> after that, do the same but search top down instead, so after (0,
> 0), go to (0, 1). discard pixels vertically upon gray. and stop.
> 
> do the same from right to left and bottom to top!
> 
> Encirclement!

You are (nearly) describing flood fill. Except that the operator
is ≠ instead of = or, perhaps you have two phases, one with
"≠ grey" and then one with "= grey" to also eliminate the doodle.

I really, strongly suggest you play around with ImageMagick and
"connected component labeling". Here[1]'s the ref, in case it
got lost in the intratubes.

Cheers

[1] https://imagemagick.org/script/connected-components.php

 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-22 Thread Emanuel Berg
David Wright wrote:

>> Encirclement!
>
> How does that work with figures like Ω or ω?

Well, if the input data doesn't make sense, why worry about the
output data?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-21 Thread Emanuel Berg
Michael uplawski wrote:

> That is a mystery which noone ever could resolve. There is
> pratically no experience with this tool and no hints have ever
> been published. I think the whole thing is utterly useless and
> that it has never made any sense to publish this stuff anyway.

It idea is super-easy, there are three types of colors. it is drop
(d, any color that isn't stop), stop (onee color), and keep (any
color). Drop is outside, keep is inside, stop is ... stop.

So this 

  d
  dddsssddd
  ddskkksdd
  ddsdd
  ssddd

will turn into this

  .
  ...sss...
  ..skkks..
  ..s..
  ss...

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-21 Thread Emanuel Berg
The Wanderer wrote:

> I think you may have misunderstood the request - either that, or
> I did.

I have posted a description how the algorithm would work.
It's really simple.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-21 Thread Emanuel Berg
tomas wrote:

>> Hello, is there a tool/command/script anywhere that can
>> overwrite with a single color (or make transparent) every pixel
>> to the left, above, right, and below a certain other color?
>> 
>> e.g., if one draws a loop of black, tell the program black is
>> the border, the result would be only what is within the loop?
>
> Your request is a bit... unspecific.

I don't know what this is called. Let's say it is called 'cac' for
'cut-around-color'.

so invocation looks like this:

  $ cac gray reaper.png

(we imagine the reaper being dressed in gray, and the sky around
him in dark blue colors)

so what happens is:

start at (0, 0) - this is the top-left pixel, as you know - is
this color gray? answer: no. go to (1, 0) etc until you get to
a grey pixel. at that point, discard all pixels until then.
and don't look any further to the right on that row!

do this for all rows from left to right, top to bottom.

after that, do the same but search top down instead, so after (0,
0), go to (0, 1). discard pixels vertically upon gray. and stop.

do the same from right to left and bottom to top!

Encirclement!

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-21 Thread David Wright
On Sun 22 Nov 2020 at 03:11:21 (+0100), Emanuel Berg wrote:
> tomas wrote:
> 
> >> Hello, is there a tool/command/script anywhere that can
> >> overwrite with a single color (or make transparent) every pixel
> >> to the left, above, right, and below a certain other color?
> >> 
> >> e.g., if one draws a loop of black, tell the program black is
> >> the border, the result would be only what is within the loop?
> >
> > Your request is a bit... unspecific.
> 
> I don't know what this is called. Let's say it is called 'cac' for
> 'cut-around-color'.
> 
> so invocation looks like this:
> 
>   $ cac gray reaper.png
> 
> (we imagine the reaper being dressed in gray, and the sky around
> him in dark blue colors)
> 
> so what happens is:
> 
> start at (0, 0) - this is the top-left pixel, as you know - is
> this color gray? answer: no. go to (1, 0) etc until you get to
> a grey pixel. at that point, discard all pixels until then.
> and don't look any further to the right on that row!
> 
> do this for all rows from left to right, top to bottom.
> 
> after that, do the same but search top down instead, so after (0,
> 0), go to (0, 1). discard pixels vertically upon gray. and stop.
> 
> do the same from right to left and bottom to top!
> 
> Encirclement!

How does that work with figures like Ω or ω?

Don't misunderstand me; the figure is drawn as if with a
broad brush, and the closed loop is the entire perimeter
of the brushed area. There are good examples from the
omega wiki page drawn on:
https://en.wikipedia.org/wiki/File:Omega_uc_lc.svg

If the loop is composed of continuous pixels, then you can
scan entire lines, using a semaphore to keep track of
crossing into/out of the loop, as long as their are no
singularities (like there would be, were the Ω serifs
to be drawn as thin as one pixel).

If the loop is a polygon, then you should be calculating
whether each point is inside or outside by calculating
the angles swept out from the point to all the vertices
in turn (finishing back at the first vertex), and seeing
whether you swept out a rotation of 360° (point is
inside) or 0° (outside).

Cheers,
David.



Re: color border in image, drop everything outside of it

2020-11-15 Thread Emanuel Berg
Michael uplawski wrote:

>> Hello, is there a tool/command/script anywhere that can
>> overwrite with a single color (or make transparent) every pixel
>> to the left, above, right, and below a certain other color?
>
> -) ImageMagick and their convert-tool

OK, but how?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



Re: color border in image, drop everything outside of it

2020-11-15 Thread tomas
On Sun, Nov 15, 2020 at 06:45:19AM -0500, The Wanderer wrote:

[...]

> Ah, right, I'd missed the "color that matches" part of the phrase. That
> does significantly change the meaning of the definition at that given
> link, to something which matches much better with what I'd have expected
> the term to mean in the first place.
> 
> In that case this seems like an even less suitable match for the request
> as I parse it.
> 
> >> What I understand the request to be is for a way to replace
> >> everything *outside of* a specified region with a specified color,
> >> where the region is *not* necessarily radius-based but may
> >> potentially be freeform.
> > 
> > Yes, but then, one person's "inside" is the other person's
> > "outside". You just have to choose judiciously your start point (aka
> > "seed"). And, of course, make sure the region thusly defined is
> > connected.
> 
> I either am badly confused, or don't understand how this relates to the
> request at all.
> 
> If I'm reading the original request correctly (which I'll admit is by no
> means guaranteed), the "single color" used to draw the "loop" - i.e.,
> in the example, black - is incidental to the goal; it just defines the
> boundary of the region which is to be left unchanged. It may or not even
> be important to retain the colored perimeter line in the result; I'd
> intuitively expect not, but there could be reasons to do so.

OK, now I get your objection: the colours "outside the loop" are
many and different. Perhaps the loop's colour is "different enough"
from every other, as determined by the fuzz metrics, then you are
lucky. Perhaps not. Then a more elaborate pipeline is necessary.

> What's outside (or, if you prefer, "on the other side of") the boundary
> may well be thousands of different colors, not necessarily in any
> pattern which the program can be expected to recognize with relation to
> another. The important part of the request is wanting to overwrite all
> of that region outside the boundary - regardless of its initial color -
> with a single, specified color (for values of "color" that include full
> transparency).
> 
> I don't see how "flood fill" can fulfill that at all. My best guess
> would involve the mention at your given reference link of a "-fuzz"
> option which lets the color matching be inexact; that could potentially
> make it possible to have a "define the boundary" color which is
> sufficiently distinct from every color in the external region that the
> fill will be able to match and replace all of the latter but will reject
> and neither replace nor propagate past the former, but it seems
> improbable that it would be practical to have this distinctness hold
> true for every image you might want to process this way.
> 
> (Then again it'd also seem impractical to guarantee that whatever color
> is chosen for defining the boundary will not occur outside of the
> boundary; I think that's why I've been mostly assuming that the literal
> drawing of the boundary with a color is just part of an attempt at a
> solution to the problem, not an essential part of the problem definition
> itself.)

Yep. That's one dificculty. Got it now. OTOH, if your loop isn't
"different enough" in colour from the rest of the image, how do
you differentiate it?

ImageMagick has many other more "intelligent" operations, but to
be able to pick one, the original problem has to be more specified,
I think.

[...]

> It comes in if the relative location of the specified region compared
> against the edges of the canvas is important.
> 
> If you stay with just one image (canvas), and replace everything outside
> the specified region with a specified color, then the relative position
> of the region remains unchanged.

[...]

> Similarly for the size of the original canvas vs. that of the new,
> previously-empty image.

I must have missed the cropping part in the OP's request. But then,
once the main problem is solved, ImageMagick has tools for that.

Another, more precise possibility is to use the "connected component
labeling" [1]: you have to then "know", by image coordinates, for
example, which is the one you want to keep. Basically, a multi-level
flood fill :-)

Cheers

[1] https://imagemagick.org/script/connected-components.php

 - t



signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-15 Thread Michael uplawski
I could choose to supersede my previous message but am not sure about
the versatility of your Mail2News vv. procedures.

Michael uplawski:

> Convert is great for automating the procedure, but I venture that the
> constraints are too difficult to meet to make it work on a big number of
> pictures.
>
> At least I would be interested to be proven wrong.

looks like I am proven wrong, as the -trim option to crop exists. Never
mind.

> Michael

-- 
GnuPG rsa4096 2020-09-08 [SC] [expire : 2022-09-08]
  B31591374C4824DE872841D27D857E5045D038F8
sub   rsa4096 2020-09-08 [E] [expire : 2022-09-08]



Re: color border in image, drop everything outside of it

2020-11-15 Thread The Wanderer
On 2020-11-15 at 06:06, to...@tuxteam.de wrote:

> On Sun, Nov 15, 2020 at 05:27:49AM -0500, The Wanderer wrote:
> 
>> On 2020-11-15 at 04:38, to...@tuxteam.de wrote:
>> 
>>> On Sun, Nov 15, 2020 at 12:31:22AM +0100, Emanuel Berg wrote:
>>> 
 Hello, is there a tool/command/script anywhere that can
 overwrite with a single color (or make transparent) every pixel
 to the left, above, right, and below a certain other color?
 
 e.g., if one draws a loop of black, tell the program black is
 the border, the result would be only what is within the loop?
> 
> [...]
> 
>> I think you may have misunderstood the request - either that, or I
>> did.
>> 
>> From the description of "flood fill", what it does is replace
>> everything within a certain distance of a specified point with a
>> specified color. That maps to "fill a specified region with a
>> specified color", if the region is radius-based.
> 
> No, no. Unless you mean "distance in colour space". Look again at the
> given ref, [0].
> 
> Flood starts at a pixel, considers every neighbour [1] having the 
> same colour [2] and repeats that process for those selected
> neighbours, until all possibilities are exhausted. Optimising that is
> left as an exercise to the reader, as they say :-)
> 
> It's a "classic" in bitmap and pixmap graphics.

Ah, right, I'd missed the "color that matches" part of the phrase. That
does significantly change the meaning of the definition at that given
link, to something which matches much better with what I'd have expected
the term to mean in the first place.

In that case this seems like an even less suitable match for the request
as I parse it.

>> What I understand the request to be is for a way to replace
>> everything *outside of* a specified region with a specified color,
>> where the region is *not* necessarily radius-based but may
>> potentially be freeform.
> 
> Yes, but then, one person's "inside" is the other person's
> "outside". You just have to choose judiciously your start point (aka
> "seed"). And, of course, make sure the region thusly defined is
> connected.

I either am badly confused, or don't understand how this relates to the
request at all.

If I'm reading the original request correctly (which I'll admit is by no
means guaranteed), the "single color" used to draw the "loop" - i.e.,
in the example, black - is incidental to the goal; it just defines the
boundary of the region which is to be left unchanged. It may or not even
be important to retain the colored perimeter line in the result; I'd
intuitively expect not, but there could be reasons to do so.

What's outside (or, if you prefer, "on the other side of") the boundary
may well be thousands of different colors, not necessarily in any
pattern which the program can be expected to recognize with relation to
another. The important part of the request is wanting to overwrite all
of that region outside the boundary - regardless of its initial color -
with a single, specified color (for values of "color" that include full
transparency).

I don't see how "flood fill" can fulfill that at all. My best guess
would involve the mention at your given reference link of a "-fuzz"
option which lets the color matching be inexact; that could potentially
make it possible to have a "define the boundary" color which is
sufficiently distinct from every color in the external region that the
fill will be able to match and replace all of the latter but will reject
and neither replace nor propagate past the former, but it seems
improbable that it would be practical to have this distinctness hold
true for every image you might want to process this way.

(Then again it'd also seem impractical to guarantee that whatever color
is chosen for defining the boundary will not occur outside of the
boundary; I think that's why I've been mostly assuming that the literal
drawing of the boundary with a color is just part of an attempt at a
solution to the problem, not an essential part of the problem definition
itself.)

>> If I needed to do that, what I'd probably wind up doing is to
>> select the desired region, copy it, paste it into an empty image,
>> and adjust its position and the size of the image to suit. I don't
>> know of any tool to automate the process to any meaningful degree.
> 
> Hm. I can't follow that last one. Perhaps I haven't understood
> anything, after all (not unheard of, mind you :). Where does the
> (re-) positioning come in?

It comes in if the relative location of the specified region compared
against the edges of the canvas is important.

If you stay with just one image (canvas), and replace everything outside
the specified region with a specified color, then the relative position
of the region remains unchanged.

If you copy the region into a new image (canvas), it will be placed
wherever the program decides to put it relative to the edges of that new
canvas, which may or may not wind up having any similarity to its
location on the original 

Re: color border in image, drop everything outside of it

2020-11-15 Thread tomas
On Sun, Nov 15, 2020 at 05:27:49AM -0500, The Wanderer wrote:
> On 2020-11-15 at 04:38, to...@tuxteam.de wrote:
> 
> > On Sun, Nov 15, 2020 at 12:31:22AM +0100, Emanuel Berg wrote:
> > 
> >> Hello, is there a tool/command/script anywhere that can overwrite 
> >> with a single color (or make transparent) every pixel to the left, 
> >> above, right, and below a certain other color?
> >> 
> >> e.g., if one draws a loop of black, tell the program black is the 
> >> border, the result would be only what is within the loop?

[...]

> I think you may have misunderstood the request - either that, or I did.
> 
> From the description of "flood fill", what it does is replace everything
> within a certain distance of a specified point with a specified color.
> That maps to "fill a specified region with a specified color", if the
> region is radius-based.

No, no. Unless you mean "distance in colour space". Look again at
the given ref, [0].

Flood starts at a pixel, considers every neighbour [1] having the
same colour [2] and repeats that process for those selected neighbours,
until all possibilities are exhausted. Optimising that is left as
an exercise to the reader, as they say :-)

It's a "classic" in bitmap and pixmap graphics.

> What I understand the request to be is for a way to replace everything
> *outside of* a specified region with a specified color, where the region
> is *not* necessarily radius-based but may potentially be freeform.

Yes, but then, one person's "inside" is the other person's "outside".
You just have to choose judiciously your start point (aka "seed").
And, of course, make sure the region thusly defined is connected.

If you think your "border" (Emanuel's "black loop") extends so far as
to multiply touch your image frame (so as to yield several disconnected
regions), you better extend the image a bit in every direction somehow.

But wait! that's what ImageMagick already does... magically, with its
VirtualPixels [3], the default being 'edge', so just what we need.

The (flat) world is a sphere, after all (at least in the context of
flood fill, that is).

> If I needed to do that, what I'd probably wind up doing is to select the
> desired region, copy it, paste it into an empty image, and adjust its
> position and the size of the image to suit. I don't know of any tool to
> automate the process to any meaningful degree.

Hm. I can't follow that last one. Perhaps I haven't understood anything,
after all (not unheard of, mind you :). Where does the (re-) positioning
come in?

Cheers

[0] https://imagemagick.org/script/command-line-options.php#floodfill
[1] For some definition of neighbour
[2] "Same colour" is often too restrictive, so this is usually relaxed
   to "similar enough": that's the -fuzz parameter in [0]
[3] https://imagemagick.org/script/architecture.php#virtual-pixels

 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-15 Thread Michael uplawski
The Wanderer:
> If I needed to do that, what I'd probably wind up doing is to select the
> desired region, copy it, paste it into an empty image, and adjust its
> position and the size of the image to suit.

For the occasional cropping task this is a fine solution.

> I don't know of any tool to
> automate the process to any meaningful degree.

Gimp does a great job offering a tool to select the region which must be
retained. A simple click later, you are done.

Convert is great for automating the procedure, but I venture that the
constraints are too difficult to meet to make it work on a big number of
pictures.

At least I would be interested to be proven wrong.

Michael

-- 
GnuPG rsa4096 2020-09-08 [SC] [expire : 2022-09-08]
  B31591374C4824DE872841D27D857E5045D038F8
sub   rsa4096 2020-09-08 [E] [expire : 2022-09-08]



Re: color border in image, drop everything outside of it

2020-11-15 Thread Jeremy Ardley


On 15/11/20 6:27 pm, The Wanderer wrote:

On 2020-11-15 at 04:38, to...@tuxteam.de wrote:


On Sun, Nov 15, 2020 at 12:31:22AM +0100, Emanuel Berg wrote:


Hello, is there a tool/command/script anywhere that can overwrite
with a single color (or make transparent) every pixel to the left,
above, right, and below a certain other color?

e.g., if one draws a loop of black, tell the program black is the
border, the result would be only what is within the loop?

Your request is a bit... unspecific.

Are you (a) after a tool which you use interactively, where you
actually see the image you described above, and where you can click
into that loop to start the operation?

Or is it (b) rather some kind or "batch mode", where you give the
program the image file *plus* the coordinates of that point inside
the loop where to start?

For ease of search, the operation you're describing is usually called
"flood fill". If you are after (a), your friend is The Gimp; I guess
Krita will fill that bill as well. If it's (b), the usual standard is
"mogrify", from the ImageMagick suite. Look at [1] for the details on
flood fill.

I think you may have misunderstood the request - either that, or I did.

 From the description of "flood fill", what it does is replace everything
within a certain distance of a specified point with a specified color.
That maps to "fill a specified region with a specified color", if the
region is radius-based.

What I understand the request to be is for a way to replace everything
*outside of* a specified region with a specified color, where the region
is *not* necessarily radius-based but may potentially be freeform.

If I needed to do that, what I'd probably wind up doing is to select the
desired region, copy it, paste it into an empty image, and adjust its
position and the size of the image to suit. I don't know of any tool to
automate the process to any meaningful degree.



The requirement seems to be to infill an image inside a bounding line.

This is what happens in postscript rendering when a raster algorithm 
scans a page containing a path defined by some geometry e.g. Bezler 
curve, and every time it crosses the curve on a scan line it changes 
from writing nothing to writing the infill color and back again at the 
next curve intersection


This happens on every character on every page you print on a postscript 
printer. It's a really basic image algorithm.


If it's possible from a script I'm not sure? but it's so simple it's 
very likely





OpenPGP_0xFABD47B0F98E88C9.asc
Description: application/pgp-keys


OpenPGP_signature
Description: OpenPGP digital signature


Re: color border in image, drop everything outside of it

2020-11-15 Thread mick crane

On 2020-11-15 09:38, to...@tuxteam.de wrote:

On Sun, Nov 15, 2020 at 12:31:22AM +0100, Emanuel Berg wrote:

Hello, is there a tool/command/script anywhere that can overwrite
with a single color (or make transparent) every pixel to the left,
above, right, and below a certain other color?

e.g., if one draws a loop of black, tell the program black is the
border, the result would be only what is within the loop?


Your request is a bit... unspecific.

Are you (a) after a tool which you use interactively, where you
actually see the image you described above, and where you can
click into that loop to start the operation?

Or is it (b) rather some kind or "batch mode", where you give the
program the image file *plus* the coordinates of that point inside
the loop where to start?

For ease of search, the operation you're describing is usually
called "flood fill". If you are after (a), your friend is The Gimp;
I guess Krita will fill that bill as well. If it's (b), the usual
standard is "mogrify", from the ImageMagick suite. Look at [1] for
the details on flood fill.

Getting warm with the ImageMagick programs takes a bit of practice,
but it's worth it. Come back if you get stuck.

Cheers
[1] https://imagemagick.org/script/command-line-options.php#floodfill
 - t


I needs to be scripted tho' if want the (x-1, x+1, y-1, y+1)s to be 
wants to be a particular value ?

mick


--
Key ID4BFEBB31



Re: color border in image, drop everything outside of it

2020-11-15 Thread The Wanderer
On 2020-11-15 at 04:38, to...@tuxteam.de wrote:

> On Sun, Nov 15, 2020 at 12:31:22AM +0100, Emanuel Berg wrote:
> 
>> Hello, is there a tool/command/script anywhere that can overwrite 
>> with a single color (or make transparent) every pixel to the left, 
>> above, right, and below a certain other color?
>> 
>> e.g., if one draws a loop of black, tell the program black is the 
>> border, the result would be only what is within the loop?
> 
> Your request is a bit... unspecific.
> 
> Are you (a) after a tool which you use interactively, where you 
> actually see the image you described above, and where you can click
> into that loop to start the operation?
> 
> Or is it (b) rather some kind or "batch mode", where you give the 
> program the image file *plus* the coordinates of that point inside 
> the loop where to start?
> 
> For ease of search, the operation you're describing is usually called
> "flood fill". If you are after (a), your friend is The Gimp; I guess
> Krita will fill that bill as well. If it's (b), the usual standard is
> "mogrify", from the ImageMagick suite. Look at [1] for the details on
> flood fill.

I think you may have misunderstood the request - either that, or I did.

From the description of "flood fill", what it does is replace everything
within a certain distance of a specified point with a specified color.
That maps to "fill a specified region with a specified color", if the
region is radius-based.

What I understand the request to be is for a way to replace everything
*outside of* a specified region with a specified color, where the region
is *not* necessarily radius-based but may potentially be freeform.

If I needed to do that, what I'd probably wind up doing is to select the
desired region, copy it, paste it into an empty image, and adjust its
position and the size of the image to suit. I don't know of any tool to
automate the process to any meaningful degree.

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man. -- George Bernard Shaw



signature.asc
Description: OpenPGP digital signature


Re: color border in image, drop everything outside of it

2020-11-15 Thread tomas
On Sun, Nov 15, 2020 at 10:49:34AM +0100, Michael uplawski wrote:

[...]

> Let us just give up and go home, now.

I hope you enjoyed your own sarcasm.

Cheers
 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-15 Thread Michael uplawski
Emanuel Berg:
>> -) ImageMagick and their convert-tool
>
> OK, but how?

That is a mystery which noone ever could resolve. There is pratically no
experience with this tool and no hints have ever been published. I think
the whole thing is utterly useless and that it has never made any sense
to publish this stuff anyway.

Let us just give up and go home, now.

-- 
GnuPG rsa4096 2020-09-08 [SC] [expire : 2022-09-08]
  B31591374C4824DE872841D27D857E5045D038F8
sub   rsa4096 2020-09-08 [E] [expire : 2022-09-08]



Re: color border in image, drop everything outside of it

2020-11-15 Thread tomas
On Sun, Nov 15, 2020 at 12:31:22AM +0100, Emanuel Berg wrote:
> Hello, is there a tool/command/script anywhere that can overwrite
> with a single color (or make transparent) every pixel to the left,
> above, right, and below a certain other color?
> 
> e.g., if one draws a loop of black, tell the program black is the
> border, the result would be only what is within the loop?

Your request is a bit... unspecific.

Are you (a) after a tool which you use interactively, where you
actually see the image you described above, and where you can
click into that loop to start the operation?

Or is it (b) rather some kind or "batch mode", where you give the
program the image file *plus* the coordinates of that point inside
the loop where to start?

For ease of search, the operation you're describing is usually
called "flood fill". If you are after (a), your friend is The Gimp;
I guess Krita will fill that bill as well. If it's (b), the usual
standard is "mogrify", from the ImageMagick suite. Look at [1] for
the details on flood fill.

Getting warm with the ImageMagick programs takes a bit of practice,
but it's worth it. Come back if you get stuck.

Cheers
[1] https://imagemagick.org/script/command-line-options.php#floodfill
 - t


signature.asc
Description: Digital signature


Re: color border in image, drop everything outside of it

2020-11-15 Thread Michael uplawski
Emanuel Berg:
> Hello, is there a tool/command/script anywhere that can overwrite
> with a single color (or make transparent) every pixel to the left,
> above, right, and below a certain other color?

-) ImageMagick and their convert-tool
-) The Gimp
-) the list of programs that the next guy will suggest.

-- 
GnuPG rsa4096 2020-09-08 [SC] [expire : 2022-09-08]
  B31591374C4824DE872841D27D857E5045D038F8
sub   rsa4096 2020-09-08 [E] [expire : 2022-09-08]



color border in image, drop everything outside of it

2020-11-14 Thread Emanuel Berg
Hello, is there a tool/command/script anywhere that can overwrite
with a single color (or make transparent) every pixel to the left,
above, right, and below a certain other color?

e.g., if one draws a loop of black, tell the program black is the
border, the result would be only what is within the loop?

TIA

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal