Link to home
Start Free TrialLog in
Avatar of amiller177
amiller177

asked on

Extract pixel color from image

How can an image file, preferably tiff, be read so that the color value of each pixel may be identified?  The goal is to determine if a pixel in an image is black or white, so that a stream of ones and zeros may be created.
Avatar of holli
holli

ASKER CERTIFIED SOLUTION
Avatar of rj2
rj2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#!/usr/bin/perl
use Image::Magick;
$im = new Image::Magick;
$im->Read("test.tif");
$x=20;$y=20;
($red, $green, $blue, $opacity) = split /,/, $im->Get("pixel[$x,$y]");
if($red==0 && $green==0 && $blue==0) {
     print "Color is black\n";
} elsif($red==255 && $green==255 && $blue==255) {
     print "Color is white\n";
} else {
     print "Color is $red,$green,$blue\n";
}