Linux create Image pixel by pixel in command line
Asked Answered
L

2

5

Is there a way in Linux to create an image and construct it pixel by pixel directly in command line?

I tried imagemagick, but its only possible to create a blank image without set pixels seperate.

Any Idea?

Load answered 4/10, 2016 at 20:6 Comment(1)
Yes, but your question is very unclear. Please give an example. You have a pixel - where from? Where do you want to put it? How many do you have? Why don't you want to add them all at the same time?Ursulina
J
5

You can use shell scripting to build a ppm image.

echo "P2"
echo "# Column (width) Row (height)"
echo "$1 $1\n1"

t=`expr $1 / 8`
for i in `seq 1 4`; do
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "1 "; done
            for i in `seq 1 $t`; do echo -n "0 "; done
        done
        echo
    done
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "0 "; done
            for i in `seq 1 $t`; do echo -n "1 "; done
        done
        echo
    done
done

To run the above code do:

$ sh filename.sh 120 > im1.ppm ; eog im1.ppm

The result is: enter image description here

Joeannjoed answered 15/4, 2018 at 23:12 Comment(0)
U
8

Ok, so we start with a red pixel:

convert xc:red image.png

I'll enlarge it - it is rather small.

enter image description here

Now we get a blue one and want to add it:

convert image.png xc:blue +append image.png

enter image description here

Then someone gives us an RGB pixel:

convert image.png xc:"rgb(255,255,0)" +append image.png

enter image description here

Now some trouble-maker comes along with an HSL pixel:

convert image.png xc:"hsl(120,100,100)" +append image.png

enter image description here

Be careful not to use JPEG though as it is lossy.

Ursulina answered 4/10, 2016 at 21:14 Comment(6)
This is clever and could totally be useful for scripts that do ad hoc visualization. How does one get to the next row in this scheme? This is the queue model, but is there a way to use convert to "Peek and Poke" colors by x, y address in an existing image as well? It is probably limited to 5 or 10 pixels a second, though.Atahualpa
That's trickier and depends on things that OP has not specified. When an extra row is added there will have to be blank/transparent pixels to fill the line since images are rectangular, so you will need to set -background none and use -append in place of +append....Ursulina
If you want to poke a blue pixel in at x,y, use convert image.png -fill blue -draw "point x,y" image.pngUrsulina
This could be awesome. Think of this: Disk IO on a one second interval, scaled by color. IO per file, where one line is added a second with a color scale for how much IO a file saw in a second or minute. A network visualization where each column is a unique address (key stored separately) with the color representing how much traffic went across the connection.. It's visually obvious when there are hot spots, and over time, patterns emerge.Atahualpa
You can do such things with awk or Perl too... https://mcmap.net/q/1923200/-create-a-png-file-from-lat-long-valueUrsulina
Ah, that would be preferable if you had a bunch of data to convert to visualization at once.Atahualpa
J
5

You can use shell scripting to build a ppm image.

echo "P2"
echo "# Column (width) Row (height)"
echo "$1 $1\n1"

t=`expr $1 / 8`
for i in `seq 1 4`; do
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "1 "; done
            for i in `seq 1 $t`; do echo -n "0 "; done
        done
        echo
    done
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "0 "; done
            for i in `seq 1 $t`; do echo -n "1 "; done
        done
        echo
    done
done

To run the above code do:

$ sh filename.sh 120 > im1.ppm ; eog im1.ppm

The result is: enter image description here

Joeannjoed answered 15/4, 2018 at 23:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.