icaoberg/Random ellipsoids

Created Sat, 07 Aug 2021 15:07:28 +0000 Modified Sat, 07 Aug 2021 15:07:28 +0000

Random ellipsoids

Yesterday I wrote a random post (see what I did there) about generating random circles using ImageMagick. Today I was thinking, what about random ellipsoids?

This should be easy to implement, I think.

Using the script I wrote yesterday,

#!/bin/bash

set -x
for I in {1..100}
do
	X=$((1 + $RANDOM % 500))
	Y=$((1 + $RANDOM % 500))
    RADIUS=$((1 + $RANDOM % 100))

	convert -size 500x500 xc:black  \
        	    -draw "fill white translate $X,$Y circle 0,0,0,$RADIUS" circles$I.png
done

montage -density 300 -tile 10x10 -geometry +5+5 -border 2 *.png montage10x10.jpg
rm -f circles*png

I can make some edits so that it generates ellipsoids and translates them randomly on the screen.

#!/bin/bash

set -x
for I in {1..100}
do
	X=$((1 + $RANDOM % 500))
	Y=$((1 + $RANDOM % 500))
        RADIUS=$((1 + $RANDOM % 100))

	convert -size 500x500 xc:black  \
        	    -draw "fill white translate $X,$Y ellipse 50,30 40,20 0,360" ellipsoid$I.png
done

montage -density 300 -tile 10x10 -geometry +5+5 -border 2 ellip*.png montage10x10.jpg
rm -f ellip*png

Montage

bash ./ellipsoid.sh  12.89s user 3.28s system 169% cpu 9.554 total

We can rebuild it… we have the technology

Introducing translation is fine, but without rotation, the ellipsoids look dull. Adding rotation

#!/bin/bash

set -x
for I in {1..100}
do
	X=$((1 + $RANDOM % 500))
	Y=$((1 + $RANDOM % 500))
        ANGLE=$((1 + $RANDOM % 360))
        RADIUS=$((1 + $RANDOM % 100))

	convert -size 500x500 xc:black  \
        	    -draw "fill white translate $X,$Y rotate $ANGLE ellipse 50,30 40,20 0,360" ellipsoid$I.png
done

montage -density 300 -tile 10x10 -geometry +5+5 -border 2 ellip*.png montage10x10-translation-and-rotation.jpg
rm -f ellip*png

makes it look better.

Montage

However, if these are meant to be synthetic primitive cells, then shape is important as well.

Make it so

Adding rotation is cool, but what about shape? I guess we can play around the parameters.

#!/bin/bash

set -x
for I in {1..100}
do
	X=$((256 + $RANDOM % 100))
	Y=$((256 + $RANDOM % 100))
        ANGLE=$((1 + $RANDOM % 360))
        X_RADIUS=$((50 + $RANDOM % 500))
        Y_RADIUS=$((50 + $RANDOM % 500))

	convert -size 1024x1024 xc:black  \
        	    -draw "fill white rotate $ANGLE ellipse $X,$Y $X_RADIUS,$Y_RADIUS 0,360" ellipsoid$I.png
done

montage -density 300 -tile 10x10 -geometry +5+5 -border 2 ellip*.png montage10x10-translation-and-rotation.png
convert montage10x10-translation-and-rotation.png -scale 50% montage10x10-translation-and-rotation.png
rm -f ellip*png

Montage

It is more than obvious this synthetic montage will not fool any cell biologist. Looks better than the first picture from yesterday’s post though.

Keep in mind $RANDOM is always sampling from a uniform distribution, so we can’t make prettier pics. An alternative is to find a package to generate random numbers from other distributions or to do this in Python. Either way, I don’t think I can make it look prettier than it is at the moment.

But why?

Bored Again I was bored. And was curious to what extent I could use ImageMagick.

These scripts are not optimized nor I claim they are. Just in case.