Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Beware of Bigfoot!


comp / comp.lang.tcl / Re: Image background

SubjectAuthor
* Image backgroundsaito
+* Re: Image backgroundRich
|+* Re: Image backgroundsaito
||`* Re: Image backgroundRich
|| `- Re: Image backgroundsaito
|`- Re: Image backgroundsaito
`* Re: Image backgroundPaul Obermeier
 `- Re: Image backgroundsaito

1
Subject: Image background
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:04 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Image background
Date: Thu, 17 Oct 2024 15:04:22 -0400
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <vern3n$2s2jq$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 21:04:24 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b21dfa98481f26b7bdf10ed197dfcd6c";
logging-data="3017338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iOmdzUbxe5ozVV69sEp6G"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+mXfbZYqi30SlnE5VGBVWjQls9U=
Content-Language: en-US
View all headers

I wonder if it is possible to remove the background from an image and
make it transparent using Tk or a package? Then I can save it as a png
image. The background in my case consists of a single color. Perhaps I
could replace that color with an "alpha" color but how?

Subject: Re: Image background
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:35 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 19:35:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <verotb$2sk50$1@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me>
Injection-Date: Thu, 17 Oct 2024 21:35:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7eaf9119ac2de22979443c99d9057602";
logging-data="3035296"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PsQMhk9QEXUPzbcB0DFf7"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:0FeULeo6x3eHuFAvriGHJFDp0hI=
View all headers

saito <saitology9@gmail.com> wrote:
> I wonder if it is possible to remove the background from an image and
> make it transparent using Tk or a package? Then I can save it as a png
> image. The background in my case consists of a single color. Perhaps I
> could replace that color with an "alpha" color but how?

man n photo:

imageName transparency subcommand ?arg arg ...?
Allows examination and manipulation of the transparency
information in the photo image. Several subcommands are
available:

imageName transparency get x y
Returns a boolean indicating if the pixel at (x,y) is
transparent.

imageName transparency set x y boolean
Makes the pixel at (x,y) transparent if boolean is true,
and makes that pixel opaque otherwise.

Subject: Re: Image background
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:44 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 15:44:41 -0400
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <verpfa$2s2jq$3@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me> <verotb$2sk50$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 21:44:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b21dfa98481f26b7bdf10ed197dfcd6c";
logging-data="3017338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//XrcJwZlnTqmGDq1Exot9"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zlJPNhRaVTff70w7pFcQrQp60eA=
Content-Language: en-US
In-Reply-To: <verotb$2sk50$1@dont-email.me>
View all headers

On 10/17/2024 3:35 PM, Rich wrote:
> saito <saitology9@gmail.com> wrote:
>> I wonder if it is possible to remove the background from an image and
>> make it transparent using Tk or a package? Then I can save it as a png
>> image. The background in my case consists of a single color. Perhaps I
>> could replace that color with an "alpha" color but how?
>
> man n photo:
>
> imageName transparency subcommand ?arg arg ...?
> Allows examination and manipulation of the transparency
> information in the photo image. Several subcommands are
> available:
>

Thank you - I missed this page. Does this command apply to non-png
images? Initially the image will have no transparency, since the
background is a solid, opaque color?

The challenge in my case is I don't know where the background starts and
what color it would be. The latter can be solved by involving the user
perhaps.

Subject: Re: Image background
From: Paul Obermeier
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:49 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: obermeier@poSoft.de (Paul Obermeier)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 21:49:27 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <verpp4$2sn6r$1@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 21:49:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e4cd3310a6bf5686e0861d4ceac7de94";
logging-data="3038427"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TorumiGyhOsX/B7xo+fLTgQfTW60ao0I="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Jvykf+i4GV+fUW2x8O2L9YPJDjs=
In-Reply-To: <vern3n$2s2jq$2@dont-email.me>
View all headers

Am 17.10.2024 um 21:04 schrieb saito:
> I wonder if it is possible to remove the background from an image and make it transparent using Tk or a package? Then I can save it as a png image. The background in my case consists of a single color. Perhaps I could replace that color with an "alpha" color but how?
>

proc SetTransparentColor { phImg { red 255 } { green 255 } { blue 255 } } {
set colorStr [format "#%02x%02x%02x" $red $green $blue]
set y 0
foreach row [$phImg data] {
set x 0
foreach pixel $row {
if { $colorStr eq $pixel } {
$phImg transparency set $x $y 1
}
incr x
}
incr y
}
}

Paul

Subject: Re: Image background
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:52 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 15:52:16 -0400
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <verpth$2s2jq$4@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me> <verotb$2sk50$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 21:52:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b21dfa98481f26b7bdf10ed197dfcd6c";
logging-data="3017338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CmzDRnJkL7goDCGFeEz+9"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jS/12dhYQJ4FFNRjOeeZFv+BX70=
In-Reply-To: <verotb$2sk50$1@dont-email.me>
Content-Language: en-US
View all headers

On 10/17/2024 3:35 PM, Rich wrote:
> imageName transparency set x y boolean
> Makes the pixel at (x,y) transparent if boolean is true,
> and makes that pixel opaque otherwise.
>

On that same page, there is a -background option which is just the
opposite of what I was looking for:

-background color
If the color is specified, the data will not contain any transparency
information. In all transparent pixels the color will be replaced by the
specified color.

Subject: Re: Image background
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:53 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 15:53:39 -0400
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <verq04$2s2jq$5@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me> <verpp4$2sn6r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 17 Oct 2024 21:53:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b21dfa98481f26b7bdf10ed197dfcd6c";
logging-data="3017338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/deLhsCFbRQEzS0GDOPU69"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:EUZMB5gtDHdDpART5Zd+hVNyl+4=
In-Reply-To: <verpp4$2sn6r$1@dont-email.me>
Content-Language: en-US
View all headers

On 10/17/2024 3:49 PM, Paul Obermeier wrote:
>
>     proc SetTransparentColor { phImg { red 255 } { green 255 } { blue
> 255 } } {
>         set colorStr [format "#%02x%02x%02x" $red $green $blue]
>         set y 0
>         foreach row [$phImg data] {
>             set x 0
>             foreach pixel $row {
>                 if { $colorStr eq $pixel } {
>                     $phImg transparency set $x $y 1
>                 }
>                 incr x
>             }
>             incr y
>         }
>     }
>
> Paul

Awesome! Thanks a lot.

Subject: Re: Image background
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 19:56 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 19:56:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <verq62$2spna$1@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me> <verotb$2sk50$1@dont-email.me> <verpfa$2s2jq$3@dont-email.me>
Injection-Date: Thu, 17 Oct 2024 21:56:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7eaf9119ac2de22979443c99d9057602";
logging-data="3041002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+t5OPw2OK53eyFmywU5Lh6"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:usxNdgzTqVy+1IHf7tkD/QlTgH0=
View all headers

saito <saitology9@gmail.com> wrote:
> On 10/17/2024 3:35 PM, Rich wrote:
>> saito <saitology9@gmail.com> wrote:
>>> I wonder if it is possible to remove the background from an image and
>>> make it transparent using Tk or a package? Then I can save it as a png
>>> image. The background in my case consists of a single color. Perhaps I
>>> could replace that color with an "alpha" color but how?
>>
>> man n photo:
>>
>> imageName transparency subcommand ?arg arg ...?
>> Allows examination and manipulation of the transparency
>> information in the photo image. Several subcommands are
>> available:
>>
>
> Thank you - I missed this page. Does this command apply to non-png
> images?

It applies to all Tk photo images.

Whether you can save the transparency to a file will depend upon the
file format you choose to save the result into.

> Initially the image will have no transparency, since the
> background is a solid, opaque color?

That depends upon what you initially load into the Tk photo. If you
load a file that can store transparency, and if Tk's image load routine
can load the transparency, you'll get whatever transparency is already
present.

> The challenge in my case is I don't know where the background starts and
> what color it would be. The latter can be solved by involving the user
> perhaps.

One option is to presume that the most common color is likely the
background, but that assumes flat, single color, backgrounds.

If by 'background' you mean something like a building behind people
posing for a photo, then you are getting very deep into advanced image
processing and/or AI image recognition to "find" the background in any
automated way.

Subject: Re: Image background
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 20:42 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: Image background
Date: Thu, 17 Oct 2024 16:42:15 -0400
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <versr8$2t5vu$1@dont-email.me>
References: <vern3n$2s2jq$2@dont-email.me> <verotb$2sk50$1@dont-email.me>
<verpfa$2s2jq$3@dont-email.me> <verq62$2spna$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 22:42:16 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cc7cba3eb3548b287ecf3e1e1cd096f5";
logging-data="3053566"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IKDAtRYEc/3IoL3y3YMZf"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kZtb24VoYFZBhvnD/As+5r4B/0k=
Content-Language: en-US
In-Reply-To: <verq62$2spna$1@dont-email.me>
View all headers

On 10/17/2024 3:56 PM, Rich wrote:
>> Thank you - I missed this page. Does this command apply to non-png
>> images?
>
> It applies to all Tk photo images.
>
> Whether you can save the transparency to a file will depend upon the
> file format you choose to save the result into.
>

Thank you. I know image processing is a rabbit hole. My question was
much simpler. I wanted to determine what the background color is (if
possible, and it is ok if not), and replace it with an alpha color. Paul
Obermeier's code answers my question perfectly.

Thanks again to both of you!

1

rocksolid light 0.9.8
clearnet tor