Display lines of numbers as image
if i have a file containing numbers that represent colours how can i display them as an image.
so file would look something like this.
Code:
#!/bin/bash
16 24 386 24 16 8 32 36
386 24 8 26 16 36 386
28 16 32 42 342 98 36 8
342 98 36 8 386 24 16 8
8 26 16 36 8 386 24 16
386 24 8 26 36 8 386 24
98 36 8 386 8 386 24 16
16 36 8 386 342 98 36 8
so each newline in the file represents a new line in the image.
please note that the numbers are only an example and probably do not represent actual colours.
spiritech
Re: Display lines of numbers as image
I don't really know what you mean... Is this some kind of format which stores images as numbers in text?
Re: Display lines of numbers as image
Please explain what you want to do!
- Do you want to make an own format for pictures (like jpeg, png ...)?
- Or do you want to create some specific output, for example an animated picture with some patterns?
I think the old icon format in Windows and the bmp (bitmap) format are primitive and maybe possible to understand from looking at the data in a hex viewer/editor.
Re: Display lines of numbers as image
Looks a bit like netpbm format: http://en.wikipedia.org/wiki/Netpbm_format
Maybe you can add a header using a text editor and make your image viewer believe it's a .pgm file. Else, you may have to write some code to convert it to something else or write your own viewer.
Re: Display lines of numbers as image
Quote:
http://ubuntuforums.org/customavatar...r1499021_1.gif sudodus
Please explain what you want to do!
- Do you want to make an own format for pictures (like jpeg, png ...)?
- Or do you want to create some specific output, for example an animated picture with some patterns?
I think the old icon format in Windows and the bmp (bitmap) format are primitive and maybe possible to understand from looking at the data in a hex viewer/editor.
what i want to do: i was hoping to be able to output those numbers to a program to generate an image. each line would (in this example) create an image 8 pixels in width and would be a totla of 8 pixels in height. i would have thought there would be a program or a way of doing this.
reason i want to do it: i figured if i had some files with many lines of values representing colours (not necessarily 8x8). i could then play around with the values using awk or something and see what happens, see what kind of results i can get.
would i really have to make my image format to do this. surely there is a program (some where) that can render values as colours line by line.
my procces would be along the lines of this. (i have written this in non code format)
Code:
read line one pass to render
read line two pass to render
read line three pass to render
welll i suppose the code would be something like this.
Code:
while read -r "value"; do "$value" render; done < value-file
i suppose i am half way there, i just need to figure out how to render the values as a picture on screen. i assume it is my graphics cards job to undrstand the values i am sending it.
Re: Display lines of numbers as image
Re: Display lines of numbers as image
I suggest that you search for imagemagick tutorial on the internet and start reading some of the good tutorials about that program package. You will find ways to use some of the tools in the imagemagick package to render the pictures you want. Start with commands as described in the tutorials and manual pages of convert, and later on maybe you can get the source code and work directly with that.
Code:
sudo apt-get install imagemagick
Edit: I'm using imagemagick convert, but I have not looked into the source code. Have a look at steeldriver's opencv, it might be be somewhere between convert and its source code in abstraction level.
Re: Display lines of numbers as image
You could also maybe take a look at opencv - perhaps python-opencv in particular, which seems to have methods to create image objects direct from numpy arrays:
http://opencv.willowgarage.com/docum...html#fromarray
[DISCLAIMER: I haven't used it, I'm just starting to play with opencv for a little image processing project]
Re: Display lines of numbers as image
have you figured out how the value=>rgb transformation is supposed to look like?
in python it's trivial
Code:
#!/usr/bin/env python
import Image
size = 8, 8
data = [ <array of pixel values> ] # figure this out and you are set
img = Image.new( "RGB", size )
img.putdata( data )
img.save( "file.png" )
i wrote 2 different functions for the tranformations, one in grayscale scaling all values down so max value becomes 255 and another that assumes R=255*hundreds/10, G=255*tens/10, B=255*ones/10 and i got abstract pixel soups :)
Code:
src = [ ... ] # input data
def f1( x, mx ):
return ( x*255/mx, x*255/mx, x*255/mx )
data1 = [ f1(x,max(src)) for x in src ]
def f2( x ):
return (255*(x%1000)/1000, 255*(x%100)/100, 255*(x%10)/10 )
data2 = [ f2(x) for x in src ]
Re: Display lines of numbers as image
Quote:
Originally Posted by
steeldriver
You could also maybe take a look at opencv
+1
Code:
sudo apt-get install libcv2.3 python-opencv python-numpy
A simple example (creates a 100x100 PNG file with a single 10x100 gray stripe at the top:
Code:
#!/urs/bin/env python
import cv
width = 100
height = 100
bit_depth = 8
channels = 3
image = cv.CreateImage((width, height), bit_depth, channels)
color = cv.RGB(127, 127, 127)
start = (0, 0)
end = (99, 9)
cv.Rectangle(image, start, end, color, -1)
cv.SaveImage("test.png", image)
Colors and start/end coordinates can be stored in lists of tuples. Then you can iterate over those lists in a for loop. For more info about python-opencv, see the reference guide.