Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Image Magic: Image Report

Posted on 2006-07-12
6
Medium Priority
?
269 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

971 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