Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Display lines of numbers as image

  1. #1
    Join Date
    Jan 2010
    Location
    England
    Beans
    185
    Distro
    Ubuntu

    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
    Last edited by spiritech; March 16th, 2013 at 07:26 AM.
    Keep those cups of Ubuntu comming.
    Ubuntu 12.10

  2. #2
    Join Date
    Jan 2012
    Beans
    753

    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?

  3. #3
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    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.

  4. #4
    Join Date
    Aug 2011
    Location
    52.5° N 6.4° E
    Beans
    6,822
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    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.

  5. #5
    Join Date
    Jan 2010
    Location
    England
    Beans
    185
    Distro
    Ubuntu

    Re: Display lines of numbers as image

    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.
    Last edited by spiritech; March 17th, 2013 at 12:10 PM.
    Keep those cups of Ubuntu comming.
    Ubuntu 12.10

  6. #6
    Join Date
    Jan 2010
    Location
    England
    Beans
    185
    Distro
    Ubuntu

    Re: Display lines of numbers as image

    removed
    Last edited by spiritech; March 17th, 2013 at 12:06 PM.
    Keep those cups of Ubuntu comming.
    Ubuntu 12.10

  7. #7
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    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.
    Last edited by sudodus; March 17th, 2013 at 02:15 PM. Reason: typing error; I use convert

  8. #8
    Join Date
    Apr 2012
    Beans
    7,256

    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]

  9. #9
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    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 ]
    Last edited by Vaphell; March 17th, 2013 at 02:50 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  10. #10
    prodigy_ is offline May the Ubuntu Be With You!
    Join Date
    Mar 2008
    Beans
    1,219

    Re: Display lines of numbers as image

    Quote Originally Posted by steeldriver View Post
    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.
    Last edited by prodigy_; March 17th, 2013 at 03:07 PM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •