Page 1 of 1

Extract image in data form for image processing

Posted: 2017-11-19T06:18:35-07:00
by haider87
How can i use convert or other command to extract data from my image into a required form. I will use the same data in filters and get result in exactly same manner. I will also have to convert it back to image. Are there any commands to generate pixel data (1 pixel) each line for gray scale 8bit image. For example:

0,0 56
0,1 33
0,2 98
0,3 59
.
.
.
.
1279,959 72

What I'm getting with regular command "convert image.jpg image.txt" is really bugging me. The result is something like below:

# ImageMagick pixel enumeration: 1280,960,65535,srgb
0,0: (514,514,514) #020202 srgb(2,2,2)
1,0: (6939,6939,6939) #1B1B1B srgb(27,27,27)
2,0: (10280,10280,10280) #282828 srgb(40,40,40)
3,0: (8738,8738,8738) #222222 srgb(34,34,34)
4,0: (10023,10023,10023) #272727 srgb(39,39,39)
5,0: (16962,16962,16962) #424242 grey26
6,0: (23901,23901,23901) #5D5D5D srgb(93,93,93)
7,0: (26728,26728,26728) #686868 srgb(104,104,104)
8,0: (16705,16705,16705) #414141 srgb(65,65,65)
9,0: (18761,18761,18761) #494949 srgb(73,73,73)

Re: Extract image in data form for image processing

Posted: 2017-11-19T09:28:32-07:00
by snibgo
When your external software reads "txt:" format, you can ignore the "#" onwards. When you write it, you needn't write the "#" onwards.

An alternative is to write the IM image as "-compress None pnm:", which is one text number per pixel, so the files are smaller.

Another alternative is to write your own process module in C. Then you can write whatever format you want.

Re: Extract image in data form for image processing

Posted: 2017-11-19T13:16:14-07:00
by haider87
Thank you so much for your reply. I was able to successfully extract data through this arguments "-compress None pnm:", this worked smoothly but now i dont know how to convert it back to image from same format?

Re: Extract image in data form for image processing

Posted: 2017-11-19T14:35:42-07:00
by snibgo
IM can read the PNM file. For example, from an image file toes.png, I create a text file...

Code: Select all

magick toes.png -compress None xyz.pnm
... then I edit the text file as I want (eg to change pixel values), then convert it back to a PNG:

Code: Select all

magick xyz.pnm abc.png

Re: Extract image in data form for image processing

Posted: 2017-11-19T23:03:53-07:00
by haider87
Thank you so much. I'm able to generate it now. Although I want to know how does it generates, top-to-bottom or bottom-to-top?

Re: Extract image in data form for image processing

Posted: 2017-11-20T00:14:27-07:00
by fmw42
What about left to right and right to left. You can get all combinations using -rotate 180, -flip, -flop, -transpose, -transverse.

For example bottom-right to top-left would be -rotate 180

Re: Extract image in data form for image processing

Posted: 2017-11-20T01:02:27-07:00
by snibgo
haider87 wrote:Although I want to know how does it generates, top-to-bottom or bottom-to-top?
Within the PNM file, the first row of number is the first rows of pixels. The last number in the file is the bottom-right pixel in the image.

Does that answer the question?

Re: Extract image in data form for image processing

Posted: 2017-11-20T02:21:19-07:00
by haider87
Thank you so much. Its a great application :)