Extract image in data form for image processing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
haider87
Posts: 4
Joined: 2017-11-19T06:09:44-07:00
Authentication code: 1152

Extract image in data form for image processing

Post 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)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract image in data form for image processing

Post 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.
snibgo's IM pages: im.snibgo.com
haider87
Posts: 4
Joined: 2017-11-19T06:09:44-07:00
Authentication code: 1152

Re: Extract image in data form for image processing

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract image in data form for image processing

Post 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
snibgo's IM pages: im.snibgo.com
haider87
Posts: 4
Joined: 2017-11-19T06:09:44-07:00
Authentication code: 1152

Re: Extract image in data form for image processing

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract image in data form for image processing

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract image in data form for image processing

Post 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?
snibgo's IM pages: im.snibgo.com
haider87
Posts: 4
Joined: 2017-11-19T06:09:44-07:00
Authentication code: 1152

Re: Extract image in data form for image processing

Post by haider87 »

Thank you so much. Its a great application :)
Post Reply