Page 1 of 1

generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T05:58:43-07:00
by choudhary.sushil
Hi,
I need to generate 5000 unique image files (.jpg) of 2MB size. Can anyone help me in getting the command for generation this many unique file on x86_64 GNU/Linux Operating System. I can provide a sample image file if required.

Regards,
Sushil Kumar

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T06:48:27-07:00
by snibgo
Can they all be the same size, in pixels? Then use plasma or noise to create an image. Put that inside a loop.

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T08:01:53-07:00
by choudhary.sushil
Yes Snibgo, If all files are of almost same size then it is well and good but content should not be same. i.e all images should be unique.

I will check plasma and noise function to create these images.

If any other suggestion it will be great.

Regards,
Sushil Kumar

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T08:46:42-07:00
by snibgo
For example:

Code: Select all

for (( NDX=1; $NDX<10; NDX=$NDX+1 ));
do
  echo $NDX;
  convert -size 100x100 plasma: rnd_$NDX.jpg
done;

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T08:48:05-07:00
by magick
Use plasma:fractal to generate unique images. If you need to reproduce the sequence in the future, generate a vector of random seeds for each image and use the -seed option on your command line.

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T10:32:10-07:00
by choudhary.sushil
Sure, Thanks Snibgo,

Hi Snibgo,
I am using 5 directory to run this script in parallel and each directory will generate 1000 files.So total target of 5000 files will be achieved soon.

I am sure that running from one location will generate all unique image files. Is their any change that if i run same script from 5 different directories then any image of one output directory may match in size and property of other output directory? I am using 5 directory of same machine.

Regards,
Sushil Kumar

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T11:06:52-07:00
by snibgo
With a random number generator, there is always a chance that two numbers will be the same. In fact, it is guaranteed to generate a number twice if you run it for long enough.

You can introduce a non-random sequential number to ensure they are unique. For example, set the top-left pixel to rgb(0,0,0) in the first image, rgb(0,0,1) in the next, and so on.

You don't need any randomness. Just use "xc:" to set the entire image to a solid colour.

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-18T15:59:28-07:00
by glennrp
You can ake a random threshold background image:

Code: Select all

convert -size 1024x768 xc:green -random-threshold 1x99% background.ppm
Then do this in a loop over s="0000" through "5000"

Code: Select all

convert background.ppm -fill white  -draw 'scale 4,4 gravity center text 0,0 $s' -quality 98 image$s.jpg

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-19T03:59:40-07:00
by choudhary.sushil
Hi Snibgo,
I believe i did almost same but generated files are not unique. The argument i passed is a number ( $I ). I passed value 4 so total 4X3=12 files got generated. but it seems all images generated by using one "colorBk" are of same property and size. So they are not unique.
=======================================
count=0

for colorBk in red blue green
do
echo "colorBk = $colorBk"
convert -size 1024x768 xc:$colorBk -random-threshold 1x99% background.ppm

for ((I=1; I<=$1; I++))
do
convert background.ppm -fill white -draw 'scale 4,4 gravity center text 0,0 "$I"' -quality 98 image$colorBk_$count.jpg
count=`expr $count + 1`
done

done
========================================

Please let me know if i am doing something wrong.

Regards,
Sushil Kumar

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-19T04:47:20-07:00
by snibgo
For the second convert, try:

Code: Select all

convert background.ppm -fill white -draw "scale 4,4 gravity center text 0,0 '$I'" -quality 98 image${colorBk}_$count.jpg

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-19T06:40:14-07:00
by choudhary.sushil
Thanks Snibgo,
It works.

Regards,
Sushil Kumar

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-19T09:03:20-07:00
by choudhary.sushil
For everyone who needs this code is below.

=======================================
#!/bin/sh
convert -size 1024x768 xc:green -random-threshold 1x99% background.ppm
for ((I=1; I<=5000; I++))
do
convert background.ppm -fill white -draw "scale 4,4 gravity center text 0,0 '$I'" -quality 98 /opt/Loc1/image_$I.jpg
done
exit;
=======================================

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-19T10:41:55-07:00
by glennrp
Note that "xc:green" is equivalent to "xc:#008000" not "xc:#00ff00". The latter is "lime" and would end up creating a small (18kbytes) solid lime-colored image with the number written on it.

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-06-19T10:58:03-07:00
by fmw42
glennrp wrote:Note that "xc:green" is equivalent to "xc:#008000" not "xc:#00ff00". The latter is "lime" and would end up creating a small (18kbytes) solid lime-colored image with the number written on it.
lime is also the same as green1 (not green as glennrp said). So lime and green1 are equivalent to #00ff00 or rgb(0,255,0).

Re: generate 5000+ unique image files (.jpg) of 2MB size

Posted: 2015-07-13T02:38:00-07:00
by choudhary.sushil
Thanks everyone. It was great help by all of you.