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
3
Medium Priority
?
1,276 Views
Last Modified: 2006-11-17
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
Comment
Question by:amiller177
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 1000 total points
ID: 8169939
#!/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";
}
0
 
LVL 10

Expert Comment

by:rj2
ID: 8169941
#!/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";
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question