Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

Thanks.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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 Jan 3 '13 at 3:37
    
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 Jan 3 '13 at 4:23
    
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 Jan 4 '13 at 5:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.