Image Log

Posted on 2014-03-22
Last Modified: 2014-03-30
I am trying to produce a log of all the pixels of an image file. I would like to print out the value of each pixel, one per line. I would like the R,G, and B values shown on a scale of 0-255. I have a snippet that almost does this, but returns the RGB values in a format that I am not sure how to convert to the one I need.

For example, the log should look like

0 255 255
255 0 0

This snippet produces a log file that looks like:


The fact that the output is all the same, and I know the image is not all one color, also has me thinking that it is not moving from pixel to pixel, but just reporting one pixel for each pixel in the image.

Any ideas on how to get a log file with the data that is needed?


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

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


for($row=1; $row<=$rows; $row++){
      for($i=1; $i<=$cols; $i++){
            print $image->get("pixel") . "\n ";

Open in new window

Question by:stakor
  • 4
  • 2
LVL 15

Accepted Solution

WalkaboutTigger earned 500 total points
ID: 39948327
Did you look at and try the code found at

Am thinking you are using get(pixel) incorrectly.

Author Comment

ID: 39948333
print $image->get("pixel") . "\n ";

print $image->get("$r $g $b") . "\n ";

prints about the right number of lines, but they are all blank.
LVL 15

Expert Comment

ID: 39948338
Do you also have

my ($r,$g,$b) = $myImage->rgb($index);?
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 39948435
Ok, switching gears slightly:


use Image::Magick;

my $input = new Image::Magick;
$input->Read ('file.jpg');
for $x (0..$h-1){
    for $y (0..$w-1){
      ($r,$g,$b) = split/,/, $input->get("pixel($x,$y)");
       print "$r $g $b \n";

Open in new window

This does the printing that I am looking for, but not in the format I am looking for. It is returning values like "1542", and not 0-255. Any ideas on how to get the format changed?

Author Comment

ID: 39948436
Also, as it turns out, it is reporting the same value for every pixel. The image is not all the same color. hmm.

Author Comment

ID: 39952774
Sorry, wrong topic.

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

Suggested Solutions

Title # Comments Views Activity
perl script 4 105
batch script for automated email 12 109
File Find regex problem 4 62
Perl script to delete older files 6 85
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 …
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

808 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