An application to view a ascii format matrix file as an image?

0

1

The image format is an ascii text, with numbers separated by spaces (black & white image). Per number per pixel. Is there any way to view this image by some application? I know I can write codes to view it, but I'm just wondering is there any existing software doing this.

Better open source and free.

xuhdev

Posted 2013-01-02T01:49:29.937

Reputation: 1 399

Question was closed 2016-05-01T01:36:09.193

Answers

1

You can easily convert such a text file to a PGM file by adding some header information using a text editor.

For example, the following PGM file is an 8x8 image containing 2x2 black and white checkerboard.

P2
8 8
1
0 0 1 1 0 0 1 1
0 0 1 1 0 0 1 1
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1
0 0 1 1 0 0 1 1
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0

Here, P2 defines the type of image (Portable greymap in ASCII), the next line defines the width and height and the third line defines the maximum grey level. The remaining lines are the actual image data.

PGM is one of the Netpbm formats, which have surprisingly good support on most operating systems and graphics applications due to their very simple formats.

Mike Fitzpatrick

Posted 2013-01-02T01:49:29.937

Reputation: 15 062

Thanks for your answer. However, my situation may be a little bit different. The ascii file contains a matrix with float number element, not only 0 and 1. Do you have any suggestions? Thanks. – xuhdev – 2013-01-03T03:37:32.917

There are image formats that support floating point formats but they all tend to store the data in binary rather than ASCII representation of floating point. PGM is the only common file format I'm aware of that supports ASCII. It will support 16 bit greyscale so if you can rescale your data (using Excel or a script maybe) to integers between 0 and 65535 then PGM would still be viable. – Mike Fitzpatrick – 2013-01-03T04:23:24.457

Thanks. I think it might be easier for me to write a script to render the image directly than convert it into an existing format. – xuhdev – 2013-01-04T05:33:55.880