[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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



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


Reply to: