Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Image Magic: Image Report

Posted on 2006-07-12
6
Medium Priority
?
265 Views
Last Modified: 2008-03-17
This is kind of an oddball question, but if you know imagemagic, I imagine it is an easy one. (Could be wrong)

What I would like to do is to have image magic read each pixel of and image, and report the RGB value in html usable form. (ie: 00FF33) On top of that, I would like to print a blurb at the beginning and the end of each "row" of pixels.

So output of a 4 pixel image might be:

begin_row
112233 112233
end_row
begin_row
FF44DD AABBC9
end_row

It is important that it be easy to decipher where I might be able to add something to the beginning or end of the RGB numbers printed out. (I will probably edit the output eventually)

Any ideas on how to print HTML values for each pixel, with a blurb for beginning and ending a row in the image?
0
Comment
Question by:stakor
[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
  • 4
6 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 1804 total points
ID: 17095511
I haven't tested this... but it should be pretty close.
I'm not sure the format the get: pixel returns.  The documentation made it sound like it is already in hex, so you should be all good.  If it returns an integer array (1 element for red, green, blue), you can use this instead:
    printf "%x%x%x ", $image->get("pixel[$row,$col]");




#!/usr/local/bin/perl

use Image::Magick;
my($image, $x);

$image = Image::Magick->new;
$x = $image->Read('file.jpg');
warn "$x" if "$x";



$cols=$image->get('columns');
$rows=$image->get('rows');

for($row=1; $row<=$rows; $row++){
      print "begin_row\n";
      for($i=1; $i<=$cols; $i++){
            print $image->get("pixel[$row,$col]") . " ";
      }
      print "\nend_row\n";
}

0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17096967
>> Any ideas on how to print HTML values for each pixel

What do you mean by HTML values?

0
 

Author Comment

by:stakor
ID: 17101266
As far as the HTML Values, I was talking about the Hex values 0-255 for RGB. 00-FF So "00 R 11 G FF B" = "0011FF"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:stakor
ID: 17101750
The results when I run Adam's program are like:

begin_row
3598,5140,2056,0 ....
end_row

I imagine the numbers are values for R G anb B, but I have no idea what the fourth one is. I was also hoping to get the numbers into hex. Any Ideas?
0
 

Author Comment

by:stakor
ID: 17102856
As it turns out I am an idiot. The incase it doesn't work, please use ____ works fine... Sorry about that. Thanks for your answer.
0
 

Author Comment

by:stakor
ID: 17104748
#!/usr/local/bin/perl

use Image::Magick;
my($image, $x);

$image = Image::Magick->new;
$x = $image->Read('file.jpg');
warn "$x" if "$x";

$cols=$image->get('columns');
$rows=$image->get('rows');

for($row=1; $row<=$rows; $row++){
     print "begin_row\n";
     for($i=1; $i<=$cols; $i++){
          printf "%x%x%x ", $image->get("pixel[$i,$row]");
     }
     print "\nend_row\n";
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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

688 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