Difference between revisions of "Converting microarray images"
m (Caretaker: Format cat links) |
(Change source-code blocks to standard format) |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
Microarray images are generally stored as 16-bit [[Wikipedia:TIFF|TIFF]] images (usually around 100Mb in size. An alternative lossy image format is [[wikipedia:JPEG|JPEG]] format, which is still bloated at around 40Mb filesize. Investigating the image size of a typical GenePix derived JPEG image, the pixel size is 4400 × 14300 pixels (72 pixels per inch) with an aspect ratio of 3.25 . A general visual summary of these lossy images is all that is required where they could be converted to a much smaller [[Wikipedia:PNG|PNG]] image type using an appropriate program such as [[Wikipedia:ImageMagick|ImageMagick]] or [[Wikipedia:GIMP|Gimp]] which allows batch processing of multiple images a once. | Microarray images are generally stored as 16-bit [[Wikipedia:TIFF|TIFF]] images (usually around 100Mb in size. An alternative lossy image format is [[wikipedia:JPEG|JPEG]] format, which is still bloated at around 40Mb filesize. Investigating the image size of a typical GenePix derived JPEG image, the pixel size is 4400 × 14300 pixels (72 pixels per inch) with an aspect ratio of 3.25 . A general visual summary of these lossy images is all that is required where they could be converted to a much smaller [[Wikipedia:PNG|PNG]] image type using an appropriate program such as [[Wikipedia:ImageMagick|ImageMagick]] or [[Wikipedia:GIMP|Gimp]] which allows batch processing of multiple images a once. | ||
− | =Imagemagick= | + | = Imagemagick = |
Once installed, all image magick tools are accessed through the command line. The ''[http://www.imagemagick.org/script/identify.php identify]'' binary describes the format and characteristics of one or more image files. e.g. | Once installed, all image magick tools are accessed through the command line. The ''[http://www.imagemagick.org/script/identify.php identify]'' binary describes the format and characteristics of one or more image files. e.g. | ||
− | < | + | <source lang="bash"> |
− | + | identify rose.jpg | |
− | + | rose.jpg JPEG 640x480 DirectClass 87kb 0.050u 0:01 | |
− | </ | + | </source> |
The ''[http://www.imagemagick.org/script/convert.php convert]'' binary is useful for resizing images, for example; | The ''[http://www.imagemagick.org/script/convert.php convert]'' binary is useful for resizing images, for example; | ||
− | < | + | <source lang="bash"> |
− | + | convert -size 800x600 input.jpg'[80x60]' output.png | |
− | + | convert input.jpg --resize 80x60 output.png | |
− | + | convert input.jpg --resize 10% output.png | |
− | + | convert input.jpg -resize 8% -quality 0 output.png | |
− | </ | + | </source> |
will resize and convert a [[wikipedia:JPEG|JPEG]] to a [[wikipedia:PNG|PNG]]. The ''[http://www.imagemagick.org/script/mogrify.php mogrify]'' binary will convert an entire directory of images; | will resize and convert a [[wikipedia:JPEG|JPEG]] to a [[wikipedia:PNG|PNG]]. The ''[http://www.imagemagick.org/script/mogrify.php mogrify]'' binary will convert an entire directory of images; | ||
− | < | + | <source lang="bash"> |
− | + | mogrify -format png -size 800x600 *.jpg # reverse input/output order | |
− | + | mogrify -format png -resize 8% -rotate -90 *.jpg | |
− | </ | + | </source> |
''Note- This appears to be memory hungry for a directory with images of large file size. In this case use the bash binary 'xargs' of a for loop, for example; | ''Note- This appears to be memory hungry for a directory with images of large file size. In this case use the bash binary 'xargs' of a for loop, for example; | ||
<table class=document-code><tr><td> | <table class=document-code><tr><td> | ||
− | < | + | <source lang="bash"> |
− | + | # Use a shell loop | |
mkdir thumbnails | mkdir thumbnails | ||
for $f in *.jpg | for $f in *.jpg | ||
Line 34: | Line 34: | ||
# the -prune option, as well as doing other file checks (like imgae type, | # the -prune option, as well as doing other file checks (like imgae type, | ||
# or the disk space used by an image). | # or the disk space used by an image). | ||
− | find * | + | find * -name '*.jpg' \ |
-exec convert '{}' -thumbnail 200x90 thumbnails/'{}'.gif \; | -exec convert '{}' -thumbnail 200x90 thumbnails/'{}'.gif \; | ||
Line 44: | Line 44: | ||
# is the simpler (without needing a sub-shell) form... | # is the simpler (without needing a sub-shell) form... | ||
ls *.jpg | xargs -I FILE convert FILE -thumbnail 200x90 th_FILE.gif | ls *.jpg | xargs -I FILE convert FILE -thumbnail 200x90 th_FILE.gif | ||
− | </ | + | </source> |
− | |||
− | ==Commands for microarray images== | + | == Commands for microarray images == |
− | < | + | <source lang="bash"> |
− | + | # Use a BASH shell loop | |
dir=PNG | dir=PNG | ||
if [ ! -d $dir ] ; then | if [ ! -d $dir ] ; then | ||
− | mkdir | + | mkdir $dir |
fi | fi | ||
for file in *.jpg | for file in *.jpg | ||
do | do | ||
echo "[ Converting $file ]" | echo "[ Converting $file ]" | ||
− | convert "$file" -resize 7% -rotate -90 -quality 0 | + | convert "$file" -resize 7% -rotate -90 -quality 0 $dir/"${file%%\.jpg}.png" |
done | done | ||
− | </ | + | </source> |
+ | The bash script need to be put somewhere so it can be called from inside the directory of all the JPEG files; | ||
+ | <source lang="bash"> | ||
+ | ../convert_images dir=PNG | ||
+ | </source> | ||
+ | |||
''Note- The original source quality influences the cut down PNG's here. Ideally JPEG's of the highest possible quality should go into making cut down PNG's since the original TIFF's are proprietary 26-bit format'' | ''Note- The original source quality influences the cut down PNG's here. Ideally JPEG's of the highest possible quality should go into making cut down PNG's since the original TIFF's are proprietary 26-bit format'' | ||
It may be necessary to remove metadata using tools such as [[Wikipedia:OptiPNG|OptiPNG]] or [[Wikipedia:Pngcrush|Pngcrush]] | It may be necessary to remove metadata using tools such as [[Wikipedia:OptiPNG|OptiPNG]] or [[Wikipedia:Pngcrush|Pngcrush]] | ||
− | ==Usage example== | + | |
+ | ;Converting PNG's | ||
+ | <source lang="bash"> | ||
+ | # Use a BASH shell loop | ||
+ | in=png | ||
+ | out=png | ||
+ | dir=PNG | ||
+ | |||
+ | if [ ! -d $dir ] ; then | ||
+ | mkdir $dir | ||
+ | fi | ||
+ | for file in *.$in | ||
+ | do | ||
+ | echo "[ Converting $file ]" | ||
+ | convert "$file" -resize 135x135 -quality 0 $dir/"${file%%\.$in}.$out" | ||
+ | done | ||
+ | </source> | ||
+ | |||
+ | == Usage example == | ||
Using wiki tables, targets files can include actual images for quick visual inspection. | Using wiki tables, targets files can include actual images for quick visual inspection. | ||
<table document-code><tr><td> | <table document-code><tr><td> | ||
Line 69: | Line 91: | ||
</table> | </table> | ||
− | =See also= | + | = See also = |
*[http://www.imagemagick.org/script/index.php ImageMagick website] | *[http://www.imagemagick.org/script/index.php ImageMagick website] | ||
*[http://www.imagemagick.org/script/command-line-tools.php Command line tool help] | *[http://www.imagemagick.org/script/command-line-tools.php Command line tool help] | ||
Line 78: | Line 100: | ||
*[[Wikipedia:OptiPNG]] | *[[Wikipedia:OptiPNG]] | ||
*[[Wikipedia:Pngcrush]] | *[[Wikipedia:Pngcrush]] | ||
+ | |||
+ | [[Category:Microarray]] |
Latest revision as of 16:54, 22 May 2015
Microarray images are generally stored as 16-bit TIFF images (usually around 100Mb in size. An alternative lossy image format is JPEG format, which is still bloated at around 40Mb filesize. Investigating the image size of a typical GenePix derived JPEG image, the pixel size is 4400 × 14300 pixels (72 pixels per inch) with an aspect ratio of 3.25 . A general visual summary of these lossy images is all that is required where they could be converted to a much smaller PNG image type using an appropriate program such as ImageMagick or Gimp which allows batch processing of multiple images a once.
Imagemagick
Once installed, all image magick tools are accessed through the command line. The identify binary describes the format and characteristics of one or more image files. e.g.
identify rose.jpg
rose.jpg JPEG 640x480 DirectClass 87kb 0.050u 0:01
The convert binary is useful for resizing images, for example;
convert -size 800x600 input.jpg'[80x60]' output.png
convert input.jpg --resize 80x60 output.png
convert input.jpg --resize 10% output.png
convert input.jpg -resize 8% -quality 0 output.png
will resize and convert a JPEG to a PNG. The mogrify binary will convert an entire directory of images;
mogrify -format png -size 800x600 *.jpg # reverse input/output order
mogrify -format png -resize 8% -rotate -90 *.jpg
Note- This appears to be memory hungry for a directory with images of large file size. In this case use the bash binary 'xargs' of a for loop, for example;
Commands for microarray images
The bash script need to be put somewhere so it can be called from inside the directory of all the JPEG files;
Note- The original source quality influences the cut down PNG's here. Ideally JPEG's of the highest possible quality should go into making cut down PNG's since the original TIFF's are proprietary 26-bit format It may be necessary to remove metadata using tools such as OptiPNG or Pngcrush
Usage exampleUsing wiki tables, targets files can include actual images for quick visual inspection. See also |