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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#!/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";
}
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";
}
especially
http://search.cpan.org/author/SUMMER/Image-Base-1.07/Base.pm
http://search.cpan.org/author/KARASIK/Prima-1.09/pod/Prima/Image.pod