2.17.2: 2011-06-17

net.sf.basedb.core
Class SpotImages

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<D>
      extended by net.sf.basedb.core.ChildItem<SpotImagesData>
          extended by net.sf.basedb.core.SpotImages
All Implemented Interfaces:
AccessControlled, Identifiable

public class SpotImages
extends ChildItem<SpotImagesData>

Holds settings for creating small spot iamges from 1-3 image files and the raw data information for a single raw bioassay.

For performance and disk space reasons the spot images are placed NxN (N given by the NUM_SPOT_IMAGES constant) into JPEG files, which are put in a zip file.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Field Summary
static int NUM_SPOT_IMAGES
          The number of spot images to place side by side in each file.
static Item TYPE
          The type of item represented by this class.
 
Constructor Summary
SpotImages(SpotImagesData data)
           
 
Method Summary
private  RenderedImage convertTiffImage(RenderedImage image, byte[] conversionTable)
          Convert TIFF image from 16 bits to 8 bits if needed
 void createSpotImages(File spotImagesFile, int xScale, int yScale, int xOffset, int yOffset, int spotsize, float gamma, float quality, File redImageFile, File greenImageFile, File blueImageFile, ProgressReporter progress)
          Creates spot images with 8 bits per channel, from source images.
 void disconnectSpotImages()
          Disconnects the generated spot image file from this item.
 File getBlueImageFile()
          Get the file which was used for the blue channel in the spot images.
 float getGamma()
          Get the gamma correction value.
 File getGreenImageFile()
          Get the file which was used for the green channel in the spot images.
(package private) static SpotImages getNew(DbControl dc, RawBioAssay rawBioAssay)
          Create a new Image item.
 float getQuality()
          Get the quality used for the jpeg compression.
 RawBioAssay getRawBioAssay()
          Get the raw bioassay the spot images belongs to.
 File getRedImageFile()
          Get the file which was used for the red channel in the spot images.
(package private)  SharedData getSharedParent()
          Get the shareable parent item of this child item.
 SpotImage getSpotImage(RawData data)
          Get a spot as a PNG image.
 List<SpotImage> getSpotImages(List<RawData> data)
          Get a list of spot PNG images from a list of RawData.
 File getSpotImagesFile()
          Get the file which holds the spot images.
 int getSpotsize()
          Get the size of the spots in pixels.
 Item getType()
          Get the type of item represented by the object.
 int getXOffset()
          Get the X-axis offset used to convert data coordinates to image pixel values: xPixel = (xData - xOffset) / xScale.
 int getXScale()
          Get the X-axis scale factor used to convert data coordinates to image pixel values: xPixel = (xData - xOffset) / xScale.
 int getYOffset()
          Get the Y-axis offset used to convert data coordinates to image pixel values: yPixel = (yData - yOffset) / yScale.
 int getYScale()
          Get the Y-axis scale factor used to convert data coordinates to image pixel values: yPixel = (yData - yOffset) / yScale.
private  boolean insideImage(float x, float y, int spotsize, int width, int height)
          Check if entire spot is inside the soure image.
private  RenderedOp loadTiffImage(File file, int band)
          Loads a TIFF file and returns a RenderedOp.
private  RenderedOp mergeColorImages()
          Merge the three color images into a single image.
private  RenderedOp rescaleColors(RenderedOp image, boolean red, boolean green, boolean blue)
          Rescale the colors of the images so we use the whole 16-bit color range.
private  void saveImage(ZipOutputStream zipFileStream, String fileName, RenderedImage image, float quality)
          Saving an image as jpeg and putting it in a zip file
private  void setBlueImageFile(File blueImageFile)
           
private  void setGamma(float gamma)
           
private  void setGreenImageFile(File greenImageFile)
           
private  void setQuality(float quality)
           
(package private)  void setRawBioAssay(RawBioAssay rawBioAssay)
          Set the raw bioassay the spot images belongs to.
private  void setRedImageFile(File redImageFile)
           
private  void setSpotsize(int spotsize)
           
private  void setXOffset(int xOffset)
           
private  void setXScale(int xScale)
           
private  void setYOffset(int yOffset)
           
private  void setYScale(int yScale)
           
 
Methods inherited from class net.sf.basedb.core.ChildItem
getPermissionForWriteDeleteAndCreate, getPluginPermissions, initPermissions
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.SPOTIMAGES, getType()

NUM_SPOT_IMAGES

public static final int NUM_SPOT_IMAGES
The number of spot images to place side by side in each file. Each file contains NxN spot images.

See Also:
Constant Field Values
Constructor Detail

SpotImages

SpotImages(SpotImagesData data)
Method Detail

getNew

static SpotImages getNew(DbControl dc,
                         RawBioAssay rawBioAssay)
                  throws BaseException
Create a new Image item.

Parameters:
dc - The DbControl which will be used for permission checking and database access
rawBioAssay - The RawBioAssay to create spot images for
Returns:
The new SpotImages item
Throws:
BaseException - If there is an error
See Also:
RawBioAssay.getSpotImages()

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

getSharedParent

SharedData getSharedParent()
Description copied from class: ChildItem
Get the shareable parent item of this child item. This is used by the ChildItem.initPermissions(int, int) method to calculate the logged in user's permissions for the child item.

Specified by:
getSharedParent in class ChildItem<SpotImagesData>
Returns:
The parent item

getRawBioAssay

public RawBioAssay getRawBioAssay()
                           throws PermissionDeniedException,
                                  BaseException
Get the raw bioassay the spot images belongs to.

Returns:
The RawBioAssay item
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission
BaseException - If there is another error

setRawBioAssay

void setRawBioAssay(RawBioAssay rawBioAssay)
              throws PermissionDeniedException,
                     InvalidDataException
Set the raw bioassay the spot images belongs to. Can only be set on a new item.

Throws:
InvalidDataException - If the raw bioassay is null
PermissionDeniedException

getXScale

public int getXScale()
Get the X-axis scale factor used to convert data coordinates to image pixel values: xPixel = (xData - xOffset) / xScale. The scale is always a positive integer.


setXScale

private void setXScale(int xScale)
                throws InvalidDataException
Throws:
InvalidDataException

getYScale

public int getYScale()
Get the Y-axis scale factor used to convert data coordinates to image pixel values: yPixel = (yData - yOffset) / yScale. The scale is always a positive integer.


setYScale

private void setYScale(int yScale)
                throws InvalidDataException
Throws:
InvalidDataException

getXOffset

public int getXOffset()
Get the X-axis offset used to convert data coordinates to image pixel values: xPixel = (xData - xOffset) / xScale. The offset may be positive or negative.


setXOffset

private void setXOffset(int xOffset)

getYOffset

public int getYOffset()
Get the Y-axis offset used to convert data coordinates to image pixel values: yPixel = (yData - yOffset) / yScale. The offset may be positive or negative.


setYOffset

private void setYOffset(int yOffset)

getSpotsize

public int getSpotsize()
Get the size of the spots in pixels. The size is a positive integer.


setSpotsize

private void setSpotsize(int spotsize)
                  throws InvalidDataException
Throws:
InvalidDataException

getQuality

public float getQuality()
Get the quality used for the jpeg compression. The quality is a number between 0.0 and 1.0, with 1.0 indicating highest quality.


setQuality

private void setQuality(float quality)
                 throws InvalidDataException
Throws:
InvalidDataException

getGamma

public float getGamma()
Get the gamma correction value. The value is always greater than or equal to 1.0.


setGamma

private void setGamma(float gamma)
               throws InvalidDataException
Throws:
InvalidDataException

getRedImageFile

public File getRedImageFile()
                     throws PermissionDeniedException,
                            BaseException
Get the file which was used for the red channel in the spot images.

Returns:
A file object or null if no file was used
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission for the file
BaseException - If there is another error

setRedImageFile

private void setRedImageFile(File redImageFile)
                      throws PermissionDeniedException
Throws:
PermissionDeniedException

getGreenImageFile

public File getGreenImageFile()
                       throws PermissionDeniedException,
                              BaseException
Get the file which was used for the green channel in the spot images.

Returns:
A file object or null if no file was used
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission for the file
BaseException - If there is another error

setGreenImageFile

private void setGreenImageFile(File greenImageFile)
                        throws PermissionDeniedException
Throws:
PermissionDeniedException

getBlueImageFile

public File getBlueImageFile()
                      throws PermissionDeniedException,
                             BaseException
Get the file which was used for the blue channel in the spot images.

Returns:
A file object or null if no file was used
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission for the file
BaseException - If there is another error

setBlueImageFile

private void setBlueImageFile(File blueImageFile)
                       throws PermissionDeniedException
Throws:
PermissionDeniedException

getSpotImagesFile

public File getSpotImagesFile()
                       throws PermissionDeniedException,
                              BaseException
Get the file which holds the spot images. The file is a zip file with a number of images each holding several spots.

Returns:
A file object or null if no file exists
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission for the file
BaseException - If there is another error

disconnectSpotImages

public void disconnectSpotImages()
                          throws PermissionDeniedException,
                                 BaseException
Disconnects the generated spot image file from this item. To delete the file you must also call the DbControl.deleteItem(BasicItem) method.

Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
BaseException - If there is an error

createSpotImages

public void createSpotImages(File spotImagesFile,
                             int xScale,
                             int yScale,
                             int xOffset,
                             int yOffset,
                             int spotsize,
                             float gamma,
                             float quality,
                             File redImageFile,
                             File greenImageFile,
                             File blueImageFile,
                             ProgressReporter progress)
                      throws PermissionDeniedException,
                             InvalidDataException,
                             BaseException
Creates spot images with 8 bits per channel, from source images. The spot images is group together, 16x16, into larger images. The larger images are stored in a zip file.

Parameters:
spotImagesFile - The file which will hold the created zip file with the spot images. Any existing content will be replaced
xScale - X-axis scale factor from data values to pixel values, must be > 0
yScale - Y-axis scale factor from data values to pixel values, must be > 0
xOffset - X offset in data value, can be any value
yOffset - Y offset in data value, can be any value
spotsize - The size of the spot i pixels, must be > 0
gamma - Gamma correction value, must be > 1.0
quality - The JPEG compression qualtity, must be a value between 0.0 and 1.0
redImageFile - The file containing the image to be used for the red channel or null
greenImageFile - The file containing the image to be used for the green channel or null
blueImageFile - The file containing the image to be used for the blue channel or null
progress - A ProgressReporter object if the calling client is interested in the progress or null if not
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission for the raw bioassay or to the specified spot images file or doesn't have use permission for any of the image files
InvalidDataException - If the directory or file name is null or all image files are null, or any of the other values are out of range
ItemAlreadyExistsException - If a file with the same name already exists in the directory
BaseException - If there is another error

getSpotImage

public SpotImage getSpotImage(RawData data)
                       throws InvalidDataException,
                              ItemNotFoundException,
                              BaseException
Get a spot as a PNG image. It is returned as a SpotImage.

Parameters:
data - A RawData object representing the spot
Returns:
SpotImage as a PNG image
Throws:
InvalidDataException - If the data object is null
ItemNotFoundException - If a spot image for the position is not found
BaseException - If there is another error

getSpotImages

public List<SpotImage> getSpotImages(List<RawData> data)
                              throws InvalidDataException,
                                     ItemNotFoundException,
                                     PermissionDeniedException,
                                     BaseException
Get a list of spot PNG images from a list of RawData. It is returned as a list of SpotImage objects. The returned list will be mapped to the incomming list. If a spot image is not found, null will be put at its position in the list. That will make both list to always have the same size. It is more efficient having the list sorted by the RawData's position.

Parameters:
data - A list of RawData objects representing the spots
Returns:
List of SpotImage objects as PNG images
Throws:
InvalidDataException - If the list of data is null
ItemNotFoundException - If the file with the spot images is not found
PermissionDeniedException - If the logged in user doesn't have read permission for the file continaing the spot images
BaseException - If there is another error

mergeColorImages

private RenderedOp mergeColorImages()
                             throws BaseException
Merge the three color images into a single image. If any of the color files are missing an empty band will be used for that color.

Returns:
The merged image
Throws:
BaseException

rescaleColors

private RenderedOp rescaleColors(RenderedOp image,
                                 boolean red,
                                 boolean green,
                                 boolean blue)
Rescale the colors of the images so we use the whole 16-bit color range. The empty bands are not include in the calculation.

Parameters:
image - Image to rescale
red - TRUE if the red channel isn't empty and should be included in the calculation
green - TRUE if green red channel isn't empty and should be included in the calculation
blue - TRUE if the blue channel isn't empty and should be included in the calculation
Returns:
Rescaled image

loadTiffImage

private RenderedOp loadTiffImage(File file,
                                 int band)
                          throws BaseException
Loads a TIFF file and returns a RenderedOp.

Parameters:
file - A Base File object pointing to the image to be loaded
band - The index of the TIFF directory to load
Throws:
BaseException

convertTiffImage

private RenderedImage convertTiffImage(RenderedImage image,
                                       byte[] conversionTable)
                                throws BaseException
Convert TIFF image from 16 bits to 8 bits if needed

Parameters:
image - TIFF image to convert
conversionTable - Conversion table
Returns:
A RenderedOp object of the image
Throws:
BaseException - If there is an error

saveImage

private void saveImage(ZipOutputStream zipFileStream,
                       String fileName,
                       RenderedImage image,
                       float quality)
                throws IOException
Saving an image as jpeg and putting it in a zip file

Parameters:
zipFileStream - Destination stream to where the JPEG is saved to
fileName - The filename of the image
image - The image to be saved
quality - The quality setting of the JPEG image
Throws:
IOException

insideImage

private boolean insideImage(float x,
                            float y,
                            int spotsize,
                            int width,
                            int height)
Check if entire spot is inside the soure image.

Parameters:
x - Spot x coordinate
y - Spot y coordinate
spotsize - Spot width and height
width - Source image width
height - Source image height

2.17.2: 2011-06-17