Solved

Image Magic: Image Report

Posted on 2006-07-12
6
261 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 451 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

626 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