Ask a Question related to Perl / CGI, Design and Development.
-
Randy Kobes #1
Re: Getting Pixel color values from an image
On Mon, 07 Jul 2003 19:31:57 +0200,
mosher <mohser.news.invalid@web2news.net> wrote:[ ... ]>I've been attempting to use Perl to process an image. I've used both
>PerlMagick and GD, but I can never retreive accurate color information
>from a pixel.If you're using GD version 2 or above, does changing the trueColor>Calling '$index = $image->getPixel($x,$y);
> ($red,$green,$blue) = $image->rgb($index);'
>from GD does appear to be returning rgb colors as expected, however
>these values are different from the actual values in my image. (I know
>they are not correct values becuase the way I am generating the image
>should only result in very specific values, and I've verified the values
>using the GIMP color picker. Also if I convert the image to other
>supported formats, the image has radically different color values,
>according to getPixel().
setting via GD::Image->trueColor([0,1]) have any effect?
--
best regards,
randy kobes
Randy Kobes Guest
-
Key out a pixel color from a bitmap
hello does anyone know if its possible to set a specific pixel color to become transparent in director? i have to import a bunch of BMP's, and... -
Which is best Pixel Dimension or Resolution Pixel/inch?
Can somebody advise me on something that I'm not too sure about in Fireworks? I have many images that I want to put up on a new site. When I get... -
Little one-pixel white edges on image resizes
Why does it happen? What I means is when you resize and image, a thin white line, on the left side of the image. To get rid of it have to either... -
Converting a color negative .jpg to a color positive image .jpg in Photoshop Elements 2.0
My scanner will convert color photo negatives to a positive image which I can then adjust using Photoshop Elements. However, it is much faster to... -
Photoshop 7.0 Sliced Image Causes DreamWeaver MX Table To add 1 Pixel gif image!
Hello, I sliced my page in Photoshop 7 and did a "Save Optimized" to HTML. I opened the page in Dreamweaver MX and it looks find. I want the TABLE... -
Randal L. Schwartz #2
Re: Getting Pixel color values from an image
>>>>> "mosher" == mosher <mohser.news.invalid@web2news.net> writes:
mosher> I've been attempting to use Perl to process an image. I've used both
mosher> PerlMagick and GD, but I can never retreive accurate color information
mosher> from a pixel.
mosher> Calling '$image->Get("pixel[$x,$y]")' from Image::Magick returns an
mosher> array of length four with each element being a multiple of 257 ranging
mosher> from 0 to 65535. I'm not sure exactly how this is representing the
mosher> colors, but it is definitely not the exact color values, which is what I
mosher> need.
<http://www.stonehenge.com/merlyn/WebTechniques/col53.html>
Not necessarily the most efficient, but give it a whirl.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz Guest
-
Rob Mosher #3
Re: Getting Pixel color values from an image
Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbh499m.6pd.mgjv@verbruggen.comdyn.com.au >...
I am generating an image in using BMRT (i.e Renderman), and I know> What do you mean, it is definitely not the exact colour value?
> ImageMagick, when compiled that way, will use 2 bytes for each colour
> value. To scale that back to the more customary 1 byte, you just need
> to divide by 256. If that still does not give you what you expect,
> then you have found a serious bug in ImageMagick, and you should
> probably notify its maintainers.
>
> How did you determine that they were not the right values?
that the only blue values that should be generated are
0,12,13,37,38,63,64... Gimp verifies this. However ImageMagick gives
me every value from 0 to 255 (if I divide). I've checked the other
color values just to be sure I didn't mix up which variable is which,
but none of them holds the correct data.
I should be a bit clearer. I converted the images to other formats> Do you have any examples of what these colours are? How radically
> different are they? What format did you save the intermediate file in,
> and what colour encoding scheme did you use when you saved it? Did
> you load the file back into the GIMP to see what the colours were
> then? If you save an image with a limited palette, the GIMP might
> recolour the current palette.
using GIMP. GIMP read the same (or nearly the same for jpg) color
values from these images, but GD read completely different sets of
colors for each format. (I had to convert the orignal image in order
to use it with GD since bmrt outputs a tif).
When I printed out the blue values read by GD for the various formats
this is what I get:
xpm:
0 7 8 9 10 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
76 77 78 79 80 82 83 84 85 86 87 88 89 90 91 92 93
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
109 110 111 114
png:
4 12 20 28 36 44 52 60 68 76 84 92 100 108 116 124 172
jpg:
12 20 27 28 33 36 44 47 52 53 55 58 60 61 63 65 67 68
69 76 78 79 80 84 86 87 88 89 92 94 95 96 100 103 104
105 106 107 108 110 112 114 116 119 121 122 124 125 127
128 129 130 131 132 136 137 138 139 140 144 145 146 148
150 154 156 157 158 162 163 164 167 168 169 172 175 178
180 182 183 185 186 187 188 195 196 199 201 202 204 207
208 212 215 216 217 218 220 224 226 228 231 236 240 241
244 252
I started out using 1.38 and then switched to 2.07. The results were>
> Also, what is the version of GD you're using?
the same for each.
The image,test.tif, can be found at:>
> Could you maybe put the image you're working with somewhere where we
> can have a look at it?
[url]http://www.andrews.edu/~mosher/graphics/[/url]
I've also copied the image in jpg, xpm, and png (with only the blue
values), as well as the scripts I am using. All the relevant parts of
the script should be in the getpixel() subroutine.
Rob Mosher
Rob Mosher Guest
-
Martien Verbruggen #4
Re: Getting Pixel color values from an image
On 18 Jul 2003 17:07:12 -0700,
Rob Mosher <mosher@andrews.edu> wrote:I can't get the .pl files from there, since your web server is trying to> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbh499m.6pd.mgjv@verbruggen.comdyn.com.au >...
>
> The image,test.tif, can be found at:
> [url]http://www.andrews.edu/~mosher/graphics/[/url]
> I've also copied the image in jpg, xpm, and png (with only the blue
> values), as well as the scripts I am using. All the relevant parts of
> the script should be in the getpixel() subroutine.
execute them. Can you rename them to something it will allow to be
transferred out?
Martien
--
|
Martien Verbruggen | Blessed are the Fundamentalists, for they
| shall inhibit the earth.
|
Martien Verbruggen Guest
-
Martien Verbruggen #5
Re: Getting Pixel color values from an image
On 18 Jul 2003 17:07:12 -0700,
Rob Mosher <mosher@andrews.edu> wrote:Image::Magick only gives me values between 0 and 145, which seems to be> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbh499m.6pd.mgjv@verbruggen.comdyn.com.au >...>>> What do you mean, it is definitely not the exact colour value?
>> ImageMagick, when compiled that way, will use 2 bytes for each colour
>> value. To scale that back to the more customary 1 byte, you just need
>> to divide by 256. If that still does not give you what you expect,
>> then you have found a serious bug in ImageMagick, and you should
>> probably notify its maintainers.
>>
>> How did you determine that they were not the right values?
> I am generating an image in using BMRT (i.e Renderman), and I know
> that the only blue values that should be generated are
> 0,12,13,37,38,63,64... Gimp verifies this. However ImageMagick gives
> me every value from 0 to 255 (if I divide). I've checked the other
> color values just to be sure I didn't mix up which variable is which,
> but none of them holds the correct data.
correct. When you "verified" that you should only have blue values from that
(incomplete) set of numbers, did you check the histogram of the image?
it clearly shows that almost all values to 145 are present. If you want
to know where those "aberrant" values are, you should check the edges of
your objects. BMRT probably antialiased the result.
If you create a histogram yourself, with Image::Magick, for example,
you'll notice that the majority of blue values (almost all) are in that
set you mention. The ones that aren't are the result of antialiasing.
Run the following (rather simple-minded and inefficient) program to see
the histogram (I have excluded the black background from the count).
Note that my Image::Magick is compiled for 8 bit pixels, while yours
seems to work with 16 bit pixels. You need to take that into account
when running the program.
use warnings;
use strict;
use Image::Magick;
my $im = Image::Magick->new();
my $rc = $im->Read("/tmp/test.tif");
die $rc if $rc;
my ($w, $h) = $im->Get('width', 'height');
my %blues;
for my $y (0..($h-1))
{
for my $x (0..($w-1))
{
my $clr = $im->Get("pixel[$x,$y]");
next if $clr eq "0,0,0,0";
my $blue = (split /,/, $clr)[2];
$blues{$blue}++;
}
}
my $max = 0;
$_ > $max and $max = $_ for values %blues;
for my $val (sort {$a <=> $b} keys %blues)
{
printf "%3d %s\n", $val, '#' x (72 * $blues{$val}/$max);
}
Martien
--
|
Martien Verbruggen | Blessed are the Fundamentalists, for they
| shall inhibit the earth.
|
Martien Verbruggen Guest



Reply With Quote

