Page 1 of 1

Trying to get pixel color data for every pixel in an image

Posted: 2010-12-19T11:39:03-07:00
by merovinq
The images will be smaller like 300x60 or so on average... but the method I am using is way too slow... is there a faster way than the php example below?

Code: Select all

$image = 'test.jpg';
$imageSize = getimagesize($image);
for($w=0; $w<=$imageSize[0]; $w++){
  	for($h=0; $h<=$imageSize[1]; $h++){
  		$txt[$w][$h] = exec('convert '.$image.'[1x1+'.$w.'+'.$h.'] txt:');	
  	}
}
debug($txt);
Below is an example of how I would like the data to look. Actually just rgb values would be fine too.

Code: Select all

Array
(
    [0] => Array
        (
            [0] => 0,0: (255,255,255)  #FFFFFF  white
            [1] => 0,0: (255,255,255)  #FFFFFF  white
            [2] => 0,0: (255,255,255)  #FFFFFF  white
            [3] => 0,0: (255,255,255)  #FFFFFF  white
            [4] => 0,0: (255,255,255)  #FFFFFF  white
            [5] => 0,0: (255,255,255)  #FFFFFF  white
            [6] => 0,0: (255,255,255)  #FFFFFF  white
            [7] => 0,0: (255,255,255)  #FFFFFF  white
            [8] => 0,0: (250,250,250)  #FAFAFA  grey98
            [9] => 0,0: (255,255,255)  #FFFFFF  white
            [10] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [11] => 0,0: (255,255,255)  #FFFFFF  white
            [12] => 0,0: (255,255,255)  #FFFFFF  white
            [13] => 0,0: (248,248,248)  #F8F8F8  rgb(248,248,248)
            [14] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [15] => 0,0: (255,255,255)  #FFFFFF  white
            [16] => 0,0: (255,255,255)  #FFFFFF  white
            [17] => 0,0: (255,255,255)  #FFFFFF  white
            [18] => 0,0: (255,255,255)  #FFFFFF  white
            [19] => 0,0: (254,254,254)  #FEFEFE  rgb(254,254,254)
            [20] => 0,0: (252,252,252)  #FCFCFC  grey99
        )

    [1] => Array
        (
            [0] => 0,0: (255,255,255)  #FFFFFF  white
            [1] => 0,0: (255,255,255)  #FFFFFF  white
            [2] => 0,0: (255,255,255)  #FFFFFF  white
            [3] => 0,0: (255,255,255)  #FFFFFF  white
            [4] => 0,0: (255,255,255)  #FFFFFF  white
            [5] => 0,0: (255,255,255)  #FFFFFF  white
            [6] => 0,0: (255,255,255)  #FFFFFF  white
            [7] => 0,0: (255,255,255)  #FFFFFF  white
            [8] => 0,0: (255,255,255)  #FFFFFF  white
            [9] => 0,0: (250,250,250)  #FAFAFA  grey98
            [10] => 0,0: (250,250,250)  #FAFAFA  grey98
            [11] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [12] => 0,0: (254,254,254)  #FEFEFE  rgb(254,254,254)
            [13] => 0,0: (252,252,252)  #FCFCFC  grey99
            [14] => 0,0: (250,250,250)  #FAFAFA  grey98
            [15] => 0,0: (255,255,255)  #FFFFFF  white
            [16] => 0,0: (248,248,248)  #F8F8F8  rgb(248,248,248)
            [17] => 0,0: (248,248,248)  #F8F8F8  rgb(248,248,248)
            [18] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [19] => 0,0: (255,255,255)  #FFFFFF  white
            [20] => 0,0: (255,255,255)  #FFFFFF  white
        )
);


Re: Trying to get pixel color data for every pixel in an ima

Posted: 2010-12-19T12:42:11-07:00
by fmw42
Withdrawn -- I see you are already converting to txt: format. Sorry.


You might try converting to Netpbm form such ppm for color in ascii output format. Perhaps it will be faster. See http://netpbm.sourceforge.net/doc/ppm.html

Anthony is the expert on NetPBM. He can help you further if NetPBM seems reasonable to him as being faster

Re: Trying to get pixel color data for every pixel in an ima

Posted: 2010-12-19T18:28:17-07:00
by anthony
As you know how to get the output from the Enumerated Pixel Format (TXT:) the problem devolves down to reading and storing the output strings in a PHP array.

That is however a PHP problem not an ImageMagick Problem. However I am sure someone such as RubbleWeb can help you further.