POV-Ray : Newsgroups : povray.newusers : Defining colors from an image Server Time
29 Jul 2024 00:35:29 EDT (-0400)
  Defining colors from an image (Message 1 to 7 of 7)  
From: OpalPlanet
Subject: Defining colors from an image
Date: 3 Jul 2007 16:15:02
Message: <web.468aad2d14dc5f2d39928d3a0@news.povray.org>
Hi all -
It's been a few days since my last random question, so here we go -

Is there any way to take the color of a certain area of an image (jpeg, png,
etc.) and find out its values in rgb? Someting along the lines of the
"eyedropper" tool in Photoshop for defining custom colors?

Thanks
OpalPlanet


Post a reply to this message

From: Warp
Subject: Re: Defining colors from an image
Date: 3 Jul 2007 17:18:09
Message: <468abd11@news.povray.org>
OpalPlanet <ecs### [at] msncom> wrote:
> Is there any way to take the color of a certain area of an image (jpeg, png,
> etc.) and find out its values in rgb?

  Perhaps a bit surprisingly, there is:

// The image will extend from <0, 0, 0> to <1, 1, 0>:
#declare Image = function { pigment { image_map { jpeg "SomeImage" } } };

#declare Pixel = Image(.5, .5, 0);

#debug concat("The value at <.5, .5> is <", vstr(3, Pixel, ", ", 0, 3), ">\n")

-- 
                                                          - Warp


Post a reply to this message

From: Samuel Benge
Subject: Re: Defining colors from an image
Date: 3 Jul 2007 18:22:29
Message: <468acc25@news.povray.org>
OpalPlanet wrote:
> Is there any way to take the color of a certain area of an image (jpeg, png,
> etc.) and find out its values in rgb?

As an alternative to Warp's suggestion, you may want to try using
eval_pigment. It doesn't require you to make the pigment into a function
beforehand, but you must still pre-declare it. Here's an example:

#include "functions.inc" // Required. Include this or transforms.inc

#declare img=     // our image to test
  pigment{
   image_map{
    //sys"fish.bmp"
    tga"gold_nugget.tga"
   }
  translate -(x+y)/2   // center the image
  scale<1.33,1,1>*10   // scale the centered image
}

#declare test_color=
  eval_pigment(
   img,     // the pigment we are testing
   <0,0,0>  // The point in 3d space to test at.
            // It will test AFTER the above transformations
  );

sphere{0,.5  // a sphere to show tested color
  pigment{
   test_color                                       // this is legal
   //rgb test_color                                 // so is this
   //rgb <test_color.x, test_color.y, test_color.z> // this also works
  }
  finish{ambient 1}
}

plane{z,.5 // plane to show entire pigment
  pigment{img}
  finish{ambient 1}
}

I hope this is helpful~

~Sam


Post a reply to this message

From: OpalPlanet
Subject: Re: Defining colors from an image
Date: 3 Jul 2007 18:30:02
Message: <web.468acd0fad49873139928d3a0@news.povray.org>
That's awesome, thanks Warp!
-OpPl

Warp <war### [at] tagpovrayorg> wrote:
> OpalPlanet <ecs### [at] msncom> wrote:
> > Is there any way to take the color of a certain area of an image (jpeg, png,
> > etc.) and find out its values in rgb?
>
>   Perhaps a bit surprisingly, there is:
>
> // The image will extend from <0, 0, 0> to <1, 1, 0>:
> #declare Image = function { pigment { image_map { jpeg "SomeImage" } } };
>
> #declare Pixel = Image(.5, .5, 0);
>
> #debug concat("The value at <.5, .5> is <", vstr(3, Pixel, ", ", 0, 3), ">n")
>
> --
>                                                           - Warp


Post a reply to this message

From: Warp
Subject: Re: Defining colors from an image
Date: 3 Jul 2007 19:44:52
Message: <468adf74@news.povray.org>
Samuel Benge <stb### [at] thishotmailcom> wrote:
> As an alternative to Warp's suggestion, you may want to try using
> eval_pigment.

  Internally eval_pigment does exactly what my example, but it does it
every time you call it, and thus it's much slower. If you define a
pigment function yourself you only have to do it once and call the
same function repeatedly, which is much faster.

-- 
                                                          - Warp


Post a reply to this message

From: Samuel Benge
Subject: Re: Defining colors from an image
Date: 4 Jul 2007 01:30:24
Message: <468b3070@news.povray.org>
Warp wrote:
> Samuel Benge <stb### [at] thishotmailcom> wrote:
>> As an alternative to Warp's suggestion, you may want to try using
>> eval_pigment.
> 
>   Internally eval_pigment does exactly what my example, but it does it
> every time you call it, and thus it's much slower. If you define a
> pigment function yourself you only have to do it once and call the
> same function repeatedly, which is much faster.

Again, you teach me something I did not know. I have a certain file 
which is badly in need of this information. Thanks!

Now, to the docs! To see if I have no excuse for my ignorance :)

~Sam


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Defining colors from an image
Date: 5 Jul 2007 22:20:55
Message: <468da707@news.povray.org>
Wow, that is cool.  I was mass-measuring some images with povray for a work
application and went to the trouble in my first case of converting each one
to ASCII-format PPM's.  


Warp wrote:

> OpalPlanet <ecs### [at] msncom> wrote:
>> Is there any way to take the color of a certain area of an image (jpeg,
>> png, etc.) and find out its values in rgb?
> 
>   Perhaps a bit surprisingly, there is:
> 
> // The image will extend from <0, 0, 0> to <1, 1, 0>:
> #declare Image = function { pigment { image_map { jpeg "SomeImage" } } };
> 
> #declare Pixel = Image(.5, .5, 0);
> 
> #debug concat("The value at <.5, .5> is <", vstr(3, Pixel, ", ", 0, 3),
> #">\n")
>


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.