Generating x number of pictures - image

I need to generate pictures with a certain size (in pixels). Each picture will have an incrementing number in it. That is all that will be in the picture, a number. I've been thinking of using photoshop but I have no idea how the scripting works. Any suggestions or examples I could use?

Try using ImageMagick (http://www.imagemagick.org) and its text handling feautures (http://www.imagemagick.org/Usage/text/).

Here is a way of doing that using ImageMagick:
#!/bin/bash
for i in {0..3}; do
echo Generating $i...
convert -size 256x256 xc:black \
-gravity south -background orange -splice 0x20 -annotate +0+2 "$i" image-$i.png
done
And the result:

Related

mix single channel images into color image

each representing a channel and I want to merge them into a single one, like RGB image. The images are RAW, so no file header. I have managed to mix them with
cat imgPl0.raw imgPl1.raw imgPl2.raw >> img.rgb
but this is mixing the planes one after the other, but is there a way to do an interlaced mix ?
Maybe using imagemagick there is another way ?
Well, what I need at the output is a rgb image (not a png, sadly imagemagick is creating a png as output) containing the data interlaced. To be more explicit, cat-ing the images is going to make a rgb image plane-interlaced (that is rrrrrr...ggggggg...bbbbbbb). What I want is an operation that is creating a rgb image line-interlaced (that is rrr...ggg...bbb...rrr...ggg...bbb...rrr...ggg...bbb...). Sorry for not being explicit from the beginning.
About the data, it seems it is 12 bpp or 14 bpp little endian
ImageMagick offers a few techniques, but you'll need to be responsible for defining all the information missing from the headers. Stuff like image size, quantum depth, and colorspace.
One approach.
convert -size 70x46 -depth 8 \
r:imgPl0.raw g:imgPl1.raw b:imgPl2.raw \
-set colorspace RGB -combine -colorspace sRGB \
output.rgb
Another option is to create a blank canvas, and copy the data from the raw files over to the correct canvas channels.
convert -size 70x46 xc: -depth 8 \
r:imgPl0.raw -compose CopyRed -composite \
g:imgPl1.raw -compose CopyGreen -composite \
b:imgPl2.raw -compose CopyBlue -composite \
-colorspace sRGB output.rgb
Other examples can be found here.
Also note: I'm assuming that these .raw data files only contain single channel samples, are unsigned character color sizes, and have a 70x46 image size. YMMV
Update
Well, what I need at the output is a rgb image (not a png, sadly imagemagick is creating a png as output)
Sorry about that. Just switch output.png to output.rgb. ImageMagick will do the rest.
About the data, it seems it is 12 bpp or 14 bpp little endian
Adjust -depth from 8 to 12, or 14 bits-per-part.
There's also a -endian LSB option, but I don't think that's needed.
What I want is an operation that is creating a rgb image line-interlaced
Easy. Set the -interlace Line options.
So... My previous answer is still helpful, but just needs some additional options.
convert -size 70x46 -depth 12 \
r:imgPl0.raw g:imgPl1.raw b:imgPl2.raw \
-set colorspace RGB -combine -colorspace sRGB \
-interlace Line output.rgb
or
convert -size 70x46 xc: -depth 12 \
r:imgPl0.raw -compose CopyRed -composite \
g:imgPl1.raw -compose CopyGreen -composite \
b:imgPl2.raw -compose CopyBlue -composite \
-colorspace sRGB -interlace Line output.rgb
Hope that get's you close.
If your data is 8 bits per sample, you can do it like this which whilst not very efficient, doesn't require any code writing or compiling or anything:
#!/bin/bash
# Bytes per row
bpr=100
row=0
# Loop through all rows of file
while :; do
# Read a row from each channel and output on stdout redirected to result.rgb
for ((chan=0;chan<3;chan++)); do
dd if=imgPl${chan}.raw bs=$bpr count=1 skip=$row > row.tmp 2> /dev/null
[ ! -s row.tmp ] && exit
cat row.tmp
done
((row+=1))
done > result.rgb

color pixel count with GraphicsMagick

I need to count pixels in an image that are not background color.
I am calling this from PHP (it's from ImageMagick):
gm convert test.png -fill black +opaque "rgb(255,255,255)" -fill white -opaque "rgb(255,255,255)" -print "pixels = %[fx:w*h*mean]\n"
But it does not give any result, nothing.
I tried using histogram instead:
gm convert test.png -define histogram:unique-colors=true -format %c histogram:info.txt
That works, but gives values for every color and more details, I just need a single number please.
You have got a couple of issues here. You seem to be trying to mix GraphicsMagick with ImageMagick when they are not the same thing.
Firstly, GraphicsMagick does not have the +opaque operator that ImageMagick has.
Secondly, it doesn't have the -fx operator that ImageMagick has for doing maths.
I would suggest you move to, the more powerful, ImageMagick. Then it will work as you expect:
# Create a test image
convert -size 200x200 xc:black xc:white xc:red +append image.png
# Count the white pixels
convert image.png -fill black +opaque "rgb(255,255,255)" -print "pixels = %[fx:w*h*mean]\n" nul:
pixels = 40000
If you really, really must do it with GraphicsMagick, I can only suggest the following - which is heavily based on #GlennRanders-Pehrson answer here:
gm convert image.png +matte -matte -transparent white -operator matte negate 1 result.png
gm identify -verbose result.png | grep -EA5 "Opacity:|Geometry:" | grep -E "Mean|Geometry"
Geometry: 600x200
Mean: 43690.00 (0.6667)
Mean: 43690.00 (0.6667)
And your answer will be:
600 * 200 * (1 - 0.667)

How do I fill certain percentage by height of an image using ImageMagick commands?

I have an image with around 20% of its bottom filled with white color. But the image has some dots of other colors than white. I have 100s of such images which I would like to remove those dots from.
I have been using ImageMagick commands, and bash scripts to automate several tasks but I cannot find any command to fill certain percentage of an image from bottom by a solid color.
The dots are marked by arrow in the screenshot. A sample command or a hint would be great!
I achieved the goal by calculating the height, taking percentage (approximate) of the image's height and filling a white rectangle.
# A tool to fill up 10% of the bottom of given image
# by white color. Useful to remove unnecessary colors
# at the bottom of image.
# Usage: this_script.sh required_image.jpg
#!/bin/bash
image=$1
right=`identify -format %w $image`;
bottom=`identify -format %h $image`;
top=`expr $bottom \* 9 / 10 | bc`;
left=0
convert $image -fill white -draw "rectangle ${left},${top},${right},${bottom}" $image
This can be automated for several images in a folder like:
for img in *.jpg; do bash <script>.sh $img; done
You can do this in a single step like this:
convert in.png \
\( +clone -gravity south -crop x10% -evaluate set 100% \) \
-composite out.png
Essentially, we read in the image and then do some "aside processing" - a delightful term coined by ImageMagick guru Kurt Pfeifle. The "aside processing" starts with (\ and ends with \). In there, we clone the image (i.e. create a copy of it) and chop off the bottom 10%, which we then fill with white. At the end of the "aside processing", this white image is still in our image stack so we tell ImageMagick to composite that on top of the original.
Result:

ImageMagick and spritesheet

I'm working on a little script that generates a sprite sheet. I have 6 spritesheets and I need to re-organize them and put their content (once ordered) in a unique file.
I logically chose to use ImageMagick. But here I'm stuck.
Here is what I have so far :
convert '%d.png[0-5]' \( -crop 456x912+0+0 -crop 3x6+0+0# +append \) -append test.png
This command line takes my 6 files (0.png to 5.png) crop them, and split them into 18 sprites. Once splited, the 18 sprites are aligned horizontally and then aligned vertically with the 18 previous one.
The problem is this command seems to only aligned them horizontally. Instead of being composed of 18x6 sprites, test.png is composed by 108x1 sprites.
Any idea how to perform this in one command ?
You might try another imagemagick tool, "montage," for this one.
$ for i in `seq 1 18 `; do convert -background none -fill black -size 32x32 -pointsize 14 caption:"$i" $i.png; done
$ montage `ls ?.png` `ls ??.png` -tile 6x3 -geometry 32x32 tile.jpg

Using ImageMagick to repeat or "tile" an image

How do I tile an image using ImageMagick? I don't think I can use montage because I want the columns displaced by 50% of the original image height.
It's probably easier to show an example of what I'm trying to do:
Start with:
End with:
Thanks!
In case you want plain tiles, without shifting down the second column and the rest of the even columns, you can use this script:
convert -size 800x600 tile:Ball.jpg Tiles.jpg
(probably the majority of people landing on this question want such plain tiles, like I did)
My "Ball.jpg" is 200 x 200 pixels, so this script creates a 4x3 tile image.
For ImageMagick 7 users, replace convert with magick.
Thanks to Fred at Fred's ImageMagick Scripts, here's the solution:
infile="tile.png"
h2=`convert $infile -format "%[fx:round(h/2)]" info:`
convert $infile \( -clone 0 -roll +0+$h2 \) +append -write mpr:sometile +delete -size 1000x500 tile:mpr:sometile output.png
This is exactly what I was looking for.
Even though you did not mention anything about context of usage, I will put it here so more people are aware. Fred's scripts are for non-commercial use. I ended with an alternative solution, however, principle is the same:
Creating shifted tile by:
convert _orange_270.jpg -roll +0+135 _orange_270_r.jpg
Create a column of regular tiles:
montage _orange_270.jpg +clone +clone +clone -tile x4 -geometry +0+0 _1col.jpg
Create a column of shifted tiles:
montage _orange_270_r.jpg +clone +clone +clone -tile x4 -geometry +0+0 _2col.jpg
Combined regular and shifted columns:
montage -geometry +0+0 _1col.jpg _2col.jpg _2cols.jpg
Created full tiled image using last output from point 4:
convert _2cols.jpg -write mpr:tile +delete -size 1920x1080 tile:mpr:tile _wallpap.jpg
Result:
If on a unix-like system with ImageMagick, you could just use my script, tileimage at http://www.fmwconcepts.com/imagemagick/tileimage/index.php.
It provides numerous variations on the flipping, rotation and offsets.
If non-commercial use, then it is free, If commercial use, then contact me for a license.
Information about tiling in ImageMagick can found at http://www.imagemagick.org/Usage/canvas/#tile

Resources