Talk:Converting microarray images

From Organic Design wiki

Hi Sven, was just wondering why you are converting tiff to jpeg? Jpeg is going to introduce a lot of artifacting and I imagine this would have a very bad affect on your results. If your source is TIFF consider using the LZW compression with binary encoding to save space and then translate this directly into PNG with imagemagick. In this way the only loss will be the pixel colour rounding error introduced with the conversion from 16bpp to 8bpp. This is still a lot of error though.

Check this: wikipedia:png. It looks like the PNG format supports 48bit colour spaces, so you could keep the whole 16bits per pixel in the conversion to PNG and not have to discard any data. --Rob 12:48, 14 Sep 2006 (NZST)

The problem is that the microarray images are proprietary 16-bit TIFF images of two channels plus a whole lot of auxillary information. If I use imagemagick to examing the filetype it think there are two images and converts them both to two separate PNG's (which is not what I want). I am forced to use the software that does the scanning of these images to convert to a lossy format first before making cut down PNG's. To reduce the loss I want JPG's that are as big in filesize as possible, we start with 110Mb TIFF's and convert to 40Mb JPEG's.
$ identify AT45.tif  
AT45.tif[0] TIFF 3760x8112+0+0 PseudoClass 65536c 16-bit 116.4m 1.1u 0:02
AT45.tif[1] TIFF 3760x8112+0+0 PseudoClass 65536c 16-bit 116.4m 0.5u 0:01
( --Sven 14:52, 14 Sep 2006 (NZST)
If imagemagick understands then it's sweet. Just grab your 2 channels and assign them to R and G and leave B and A blank. That way you have a RGBA compatible colour space. Save this out as a PNG. I haven't played with imagemagick but if it can deal with channels then it can construct as many as are needed. --Rob 16:47, 14 Sep 2006 (NZST)
Not sure exacty what you mean, what package would you normally do this in? Photoshop cannot understand these images. Here is the options in Imagemagick'sconvert binary;
$ convert
Version: ImageMagick 5.5.1 10/15/02 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 2002 ImageMagick Studio LLC

Usage: Magick [options ...] file [ [options ...] file ...] [options ...] file

Where options include:
  -adjoin              join images into a single multi-image file
  -affine matrix       affine transform matrix
  -antialias           remove pixel-aliasing
  -append              append an image sequence
  -authenticate value  decrypt image with this password
  -average             average an image sequence
  -background color    background color
  -blue-primary point  chomaticity blue primary point
  -blur geometry       blur the image
  -border geometry     surround image with a border of color
  -bordercolor color   border color
  -channel type        extract a particular color channel from image <--------------------
  -charcoal radius     simulate a charcoal drawing
  -chop geometry       remove pixels from the image interior
  -clip                apply clipping path if the image has one
  -coalesce            merge a sequence of images
  -colorize value      colorize the image with the fill color
  -colors value        preferred number of colors in the image
  -colorspace type     alternate image colorspace
  -comment string      annotate image with comment
  -compress type       image compression tyhpe
  -contrast            enhance or reduce the image contrast
  -crop geometry       preferred size and location of the cropped image
  -cycle amount        cycle the image colormap
  -debug events        display copious debugging information
  -deconstruct         break down an image sequence into constituent parts
  -delay value         display the next image after pausing
  -density geometry    horizontal and vertical density of the image
  -depth value         image depth
  -despeckle           reduce the speckles within an image
  -display server      get image or font from this X server
  -dispose method      Undefined, None, Background, Previous
  -dither              apply Floyd/Steinberg error diffusion to image
  -draw string         annotate the image with a graphic primitive
  -edge radius         apply a filter to detect edges in the image
  -emboss radius       emboss an image
  -encoding type       text encoding type
  -endian type         LSB or MSB
  -enhance             apply a digital filter to enhance a noisy image
  -equalize            perform histogram equalization to an image
  -fill color          color to use when filling a graphic primitive
  -filter type         use this filter when resizing an image
  -flatten             flatten a sequence of images
  -flip                flip image in the vertical direction
  -flop                flop image in the horizontal direction
  -font name           render text with this font
  -frame geometry      surround image with an ornamental border
  -fuzz distance       colors within this distance are considered equal
  -gamma value         level of gamma correction
  -gaussian geometry   gaussian blur an image
  -geometry geometry   perferred size or location of the image
  -green-primary point chomaticity green primary point
  -gravity type        horizontal and vertical text placement
  -help                print program options
  -implode amount      implode image pixels about the center
  -intent type         Absolute, Perceptual, Relative, or Saturation
  -interlace type      None, Line, Plane, or Partition
  -label name          assign a label to an image
  -level value         adjust the level of image contrast
  -limit type value    Disk, Map, or Memory resource limit
  -list type           Color, Delegate, Format, Magic, Module, or Type
  -loop iterations     add Netscape loop extension to your GIF animation
  -map filename        transform image colors to match this set of colors
  -mask filename       set the image clip mask
  -matte               store matte channel if the image has one
  -median radius       apply a median filter to the image
  -modulate value      vary the brightness, saturation, and hue
  -monochrome          transform image to black and white
  -morph value         morph an image sequence
  -mosaic              create a mosaic from an image sequence
  -negate              replace every pixel with its complementary color 
  -noop                do not apply options to image
  -noise radius        add or reduce noise in an image
  -normalize           transform image to span the full range of colors
  -opaque color        change this color to the fill color
  -page geometry       size and location of an image canvas
  -paint radius        simulate an oil painting
  -ping                efficiently determine image attributes
  -pointsize value     font point size
  -preview type        image preview type
  -profile filename    add ICM or IPTC information profile to image
  -quality value       JPEG/MIFF/PNG compression level
  -raise value         lighten/darken image edges to create a 3-D effect
  -region geometry     apply options to a portion of the image
  -raise value         lighten/darken image edges to create a 3-D effect
  -red-primary point   chomaticity red primary point
  -render              render vector graphics
  -resize geometry     resize the image
  -roll geometry       roll an image vertically or horizontally
  -rotate degrees      apply Paeth rotation to the image
  -sample geometry     scale image with pixel sampling
  -sampling-factor geometry
                       horizontal and vertical sampling factor
  -scale geometry      scale the image
  -scene value         image scene number
  -seed value          pseudo-random number generator seed value
  -segment values      segment an image
  -shade degrees       shade the image using a distant light source
  -sharpen geometry    sharpen the image
  -shave geometry      shave pixels from the image edges
  -shear geometry      slide one edge of the image along the X or Y axis
  -size geometry       width and height of image
  -solarize threshold  negate all pixels above the threshold level
  -spread amount       displace image pixels by a random amount
  -stroke color        graphic primitive stroke color
  -strokewidth value   graphic primitive stroke width
  -swirl degrees       swirl image pixels about the center
  -texture filename    name of texture to tile onto the image background
  -threshold value     threshold the image
  -tile filename       tile image when filling a graphic primitive
  -transform           affine transform image
  -transparent color   make this color transparent within the image
  -treedepth value     color tree depth
  -trim                trim image edges
  -type type           image type
  -undercolor color    annotation bounding box color
  -units type          PixelsPerInch, PixelsPerCentimeter, or Undefined
  -unsharp geometry    sharpen the image
  -verbose             print detailed information about the image
  -version             print version information
  -view                FlashPix viewing transforms
  -virtual-pixel method
                       Constant, Edge, Mirror, or Tile
  -wave geometry       alter an image along a sine wave
  -white-point point   chomaticity white point
  -write filename      write images to this file

By default, the image format of `file' is determined by its magic
number.  To specify a particular image format, precede the filename
with an image format name and a colon (i.e. ps:image) or specify the
image type as the filename suffix (i.e. image.ps).  Specify 'file' as
'-' for standard input or output.

Have not found a merging option but there must be one somewhere (need to a color filter too). --Sven 10:07, 15 Sep 2006 (NZST)

The flatten has been tested and works, just need to add colour filters now --Sven 10:10, 15 Sep 2006 (NZST)
Not really sure what you're wanting to do here, but you should be able to just extract any channels you want and compose them into a new image any way you like. Imagenagick is very powerful and you can do any kind of image manipulation with it --Nad 09:16, 15 Sep 2006 (NZST)
I have a 16-bit microarray two channel image that is of proprietary format. I want to be able to convert it to a PNG without relying on proprietary software (which I dont have). I think imagemagick will be able to do it, but a subjective call by me will be needed to increase brightness and add red/green filters to the white spots.
It's much more flexiable using ImageMagick from PERL (PerlMagick) because then you can handle multiple channels etc as separate images and maniulate them with imageMagick methods at runtime, then write to any format at the end. --Nad 16:25, 15 Sep 2006 (NZST)
Yes that would be a nice way --Sven 17:30, 15 Sep 2006 (NZST)

File:Red.png

plus File:Green.png = File:Merged.png

--Sven 17:11, 15 Sep 2006 (NZST)

Upper, lower case issues

This code snippet works for lower and upper case extensions converting to lower --Sven 15:16, 3 February 2011 (PST)

# Use a BASH shell loop
in=jpg
out=jpg
dir=LowRes
DEBUG=''

## Check directory exists
if [ ! -d $dir ] ; then
  mkdir $dir
fi

## Loop on all case insensitive file extensions 
for file in `ls | grep -i jpg$`
do
  ## Store upper version of $in as a variable
  inUpper=$(echo $in | tr [[:lower:]] [[:upper:]])
  
  ## Sanity check;
  if [ $DEBUG ]; then
    echo $inUpper
  fi

  echo "[ Converting $file ]"
  if [ $(echo $file | grep $inUpper) ] ; then
    if [ $DEBUG ]; then
      echo U: $file 
    fi
    convert "$file" -resize 800x600 -quality 0 $dir/"${file%%\.$inUpper}.$out"
  else
    if [ $DEBUG ]; then
      echo L: $file
    fi
    convert "$file" -resize 800x600 -quality 0 $dir/"${file%%\.$in}.$out"
  fi
done