Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Extract pixel color from image

Posted on 2003-03-19
Medium Priority
1,276 Views
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.
0
Question by:amiller177
• 2

LVL 6

Expert Comment

ID: 8169562
0

LVL 10

Accepted Solution

rj2 earned 1000 total points
ID: 8169939
#!/usr/bin/perl
use Image::Magick;
\$im = new Image::Magick;
\$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";
}
0

LVL 10

Expert Comment

ID: 8169941
#!/usr/bin/perl
use Image::Magick;
\$im = new Image::Magick;
\$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";
}
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…