For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > April 2004 > convert graphic file to x,y coordinates









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author convert graphic file to x,y coordinates
Mike Solomon

2004-04-27, 2:05 am

I need to take a graphics file and then get the xy coordinates from it
and insert them into a database

so far the best way I have come up with is to use paint to get the
cordinates and manually record them in a spreadsheet

Is there any way I can use perl to read the graphics file and get the
co-ordinates

I am probably being optimistic but doing it manually is driving me mad
:)
John Bokma

2004-04-27, 2:05 am



Mike Solomon wrote:

> I need to take a graphics file and then get the xy coordinates from it
> and insert them into a database
>
> so far the best way I have come up with is to use paint to get the
> cordinates and manually record them in a spreadsheet
>
> Is there any way I can use perl to read the graphics file and get the
> co-ordinates
>
> I am probably being optimistic but doing it manually is driving me mad
> :)


What kind of graphics file, and how are xy coordinates marked?

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Gregory Toomey

2004-04-27, 2:05 am

Mike Solomon wrote:

> I need to take a graphics file and then get the xy coordinates from it
> and insert them into a database
>
> so far the best way I have come up with is to use paint to get the
> cordinates and manually record them in a spreadsheet
>
> Is there any way I can use perl to read the graphics file and get the
> co-ordinates
>
> I am probably being optimistic but doing it manually is driving me mad
> :)


Have a look at http://search.cpan.org/~lds/GD-2.12/GD.pm

Try reading in an image:

$image = GD::Image->newFromJpegData($data, [$truecolor])
$image = GD::Image->newFromPng($file, [$truecolor])
(there may be an earlier GD version that works wiht gifs)

then get the pixels
$image->getPixel(x,y)


Buy why dont you insert the whole image into the database as a binary
object?

gtomey
Sherm Pendley

2004-04-27, 2:05 am

Mike Solomon wrote:

> I need to take a graphics file and then get the xy coordinates from it
> and insert them into a database


What do you mean by "xy coordinates" - the size of the image?

If so, why didn't you try searching for "image size" on CPAN? Doing so would
have shown you the Image::Size module. It can read data from a file name,
an in-memory buffer, or an open file handle, and supports most common image
formats.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Jürgen Exner

2004-04-27, 2:06 am

Mike Solomon wrote:
> I need to take a graphics file and then get the xy coordinates from it
> and insert them into a database


What kind of graphics file are you talking about? Vector graphic? Bitmap?
BMP? JPEG? GIF? PNG? Or any other of the hundreds of lesser known formats?

For some of them you should be able to find a parser on CPAN.
If it is a vector graphic format then it should be easy to get to the xy
coordinates of whatever objects you are after in your graphic (you didn't
tell us, either).
However, if you are after the xy-coordinates of objects in bitmap graphics,
then the last time I checked that was still a very active research area and
requires quite complex picture analysis and a lot of good guesses by the
program. I doubt that there is anything on CPAN (although you never know)
and actually Perl might not be the best tool for this kind of highly
numerical analysis.

jue


Mike Solomon

2004-04-27, 5:57 am

mike_solomon@lineone.net (Mike Solomon) wrote in message news:<56568be5.0404260151.603d47bf@posting.google.com>...
> I need to take a graphics file and then get the xy coordinates from it
> and insert them into a database
>
> so far the best way I have come up with is to use paint to get the
> cordinates and manually record them in a spreadsheet
>
> Is there any way I can use perl to read the graphics file and get the
> co-ordinates
>
> I am probably being optimistic but doing it manually is driving me mad
> :)


Thanks for the replies

The files are either be jpeg or png

I will try image magic and keep my fingers crossed

The image is a stand map - basically black outlined rectangles on a
white background

I need to get the co-ordinates to pass them to a flash program and
also so I can create a printable stand map

I can't just store the image in the database as I need the
co-ordinates
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com