Reputation: 9024
I'm unsure if imagemagick is able to do this, or if I need to write something myself; but I'd like to convert an image such as the below to a text file such that each line represents a single pixel (reading left to right, top to bottom) and has 15-bits of data on each line (5 bits for R, G, and B).
So for example the below image would have 256x224 = 57,344 lines of 15-bits.
Is imagemagick capable of doing this? If not is there another resource? Appreciate any help.
Upvotes: 1
Views: 458
Reputation: 208043
This should do what you want:
convert U4zI6.png -depth 8 rgb: | perl -e '
# Read file, 3 RGB bytes at a time
{
local $/ = \3;
while(my $pixel=<STDIN>){
my ($r,$g,$b) = unpack("CCC",$pixel);
printf("In R/G/B: %d/%d/%d\n",$r,$g,$b);
my $r = ($r >> 3) & 63;
my $g = ($g >> 3) & 63;
my $b = ($b >> 3) & 63;
printf("Out R/G/B: %d/%d/%d\n",$r,$g,$b);
}
}
'
Upvotes: 1
Reputation: 12465
Just use the ".txt" output format:
magick U4zI6.png U4zI6.txt
This will have more voluminous information for each line, but you can use a text editor such as "sed" to extract the RGB values.
$ head -6 U4Zi6.txt
# ImageMagick pixel enumeration: 256,224,65535,srgb
0,0: (28784,45232,53456) #70B0D0 srgb(112,176,208)
1,0: (28784,45232,53456) #70B0D0 srgb(112,176,208)
2,0: (28784,45232,53456) #70B0D0 srgb(112,176,208)
3,0: (28784,45232,53456) #70B0D0 srgb(112,176,208)
4,0: (28784,45232,53456) #70B0D0 srgb(112,176,208)
Upvotes: 4