?
Solved

Extract pixel color from image

Posted on 2003-03-19
3
Medium Priority
?
1,219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

777 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