Extract value from a png file with coordinate

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
stefan.l
Posts: 5
Joined: 2013-09-18T08:35:22-07:00
Authentication code: 6789

Extract value from a png file with coordinate

Post by stefan.l »

Hi all IM users,

How to explain my problem ?
Well, I've got a png file which contains radar precipitation. The png size in pixel is 1536x1536 pixels.
So I would like to extract :

X Y Value like

1 0 pixelValue
2 0 pixelValue
.
.
.
etc...

In another file I have information of each od these 1536 pixels x 1536 pixels concerning coordinates
I got for this a .prj

ncols 1536
nrows 1536
xllcorner -619652.074056195910
yllcorner -5062818.337687556632
cellsize 999.999999840583
NODATA_value 63

As you can see
- We find the ncols and nrows
- We know the coordinates of the (0,0) pixels
- we know the pixels size which tell me the coordinate of each pixel.

The problem is that I'd like to extract each pixel of the png file and its Value

Do you think that there is a command to do this ?

Thank you very much for your helps.

Best regard

Stefan
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract value from a png file with coordinate

Post by snibgo »

If you want to dump the entire image to a large text file:

Code: Select all

convert in.png txt:
If you want the RGB components of just one pixel:

Code: Select all

convert in.png -precision 9 -format "ONE_PIXEL.R=%[fx:p{XX,YY}.r]\nONE_PIXEL.G=%[fx:p{XX,YY}.g]\nONE_PIXEL.B=%[fx:p{XX,YY}.b]"info:
... where XX and YY are the required integer coordinates.

Many other methods are available, including non-integer coordinates, if you need them.
snibgo's IM pages: im.snibgo.com
stefan.l
Posts: 5
Joined: 2013-09-18T08:35:22-07:00
Authentication code: 6789

Re: Extract value from a png file with coordinate

Post by stefan.l »

Hi Snibgo

I don't know how th thank you. It's so simple

convert in.png txt : :-)

The second way wil be very usefull to extract value on one pixel because as I said I can know the geographic equivalent coordinate.
Thank thank thank for you help.

May I ask If I would able to find this command in the IM command pages ?

Stefan
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract value from a png file with coordinate

Post by snibgo »

snibgo's IM pages: im.snibgo.com
stefan.l
Posts: 5
Joined: 2013-09-18T08:35:22-07:00
Authentication code: 6789

Re: Extract value from a png file with coordinate

Post by stefan.l »

Thank you very much Snibgo

Stéfan
Post Reply