org.shapelogic.imageutil
Class SLBufferedImage

java.lang.Object
  extended by org.shapelogic.imageutil.SLBufferedImage
All Implemented Interfaces:
PixelHandler, SLImage

public class SLBufferedImage
extends java.lang.Object
implements SLImage

Abstraction of ImageJ ImageProcessor.
This is an attempt to get Java BufferedImage to look like the ImageJ ImageProcessor.
They are not perfectly matched.
I think that I should make the assumption that this is either a
24 or 32 bit RGB
8 bit gray
And fail the creation if it is not.

Author:
Sami Badawi

Field Summary
protected  java.awt.image.BufferedImage _bufferedImage
           
protected  java.awt.image.DataBuffer _dataBuffer
           
protected  java.lang.String _filePath
           
protected  int _lineStride
           
protected  int _mask
           
protected  java.lang.Object _pixels
           
protected  byte[] _pixelsInBytes
           
protected  int[] _pixelsInInt
           
protected  short[] _pixelsInShort
           
protected  java.awt.image.WritableRaster _rasta
           
protected  java.awt.Rectangle _roi
           
static int INT_ALL_MASK
           
static int INT_BYTE_MASK
           
static int UNDEFINED
           
 
Constructor Summary
SLBufferedImage(java.awt.image.BufferedImage image)
           
SLBufferedImage(java.lang.String filePath)
           
SLBufferedImage(java.lang.String dir, java.lang.String fileName, java.lang.String fileFormat)
          Constructor with 3 string arguments.
 
Method Summary
 int get(int index)
           
 int get(int x, int y)
          In ImageJ this will return the byte if it is a byte gray else an encoded RGB value.
This does not work well with BufferedImage that has a method to always return the RGB.
I might have to subclass this in order to make an effective implementation.
 java.awt.Rectangle getActiveRectangle()
          The part of the image that is available in the pixels array.
A hook to only have part of the image active at the same time.
Returning null mean that the whole images is available in the pixels array.
 java.awt.image.BufferedImage getBufferedImage()
           
 int getHeight()
          Returns the height of this image in pixels.
 int getLineStride()
          Number of index position in the pixels array to jump to get to the next line.
 int getNChannels()
          Returns the number of color channels in the image.
 int getNChannelsOld()
           
 int getPixelCount()
           
 java.lang.Object getPixels()
          Returns a reference to this image's pixel array.
 byte[] getPixelsInBytes()
           
 int[] getPixelsInInt()
           
 java.awt.Rectangle getRoi()
          Not implemented for BufferedImage.
 int getWidth()
          Returns the width of this image in pixels.
 boolean isEmpty()
          Test for failed image read.
If the read of an image fails it will still create the object but _bufferedImage == null.
 boolean isGray()
           
 boolean isGray16()
           
 boolean isGray8()
           
 boolean isInvertedLut()
          Always false for a BufferedImage.
 boolean isRgb()
           
 void putPixel(int x, int y, int value)
          Stores the specified value at (x,y).
 void set(int index, int value)
           
 void set(int x, int y, int value)
          This is a faster version of putPixel() that does not clip out of range values and does not do bounds checking.
 void setPixels(java.lang.Object pixels)
          Sets a new pixel array for the image.
 void setRoi(int x, int y, int rwidth, int rheight)
           
 void setRoi(java.awt.Rectangle roi)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT_ALL_MASK

public static final int INT_ALL_MASK
See Also:
Constant Field Values

INT_BYTE_MASK

public static final int INT_BYTE_MASK
See Also:
Constant Field Values

UNDEFINED

public static final int UNDEFINED
See Also:
Constant Field Values

_bufferedImage

protected java.awt.image.BufferedImage _bufferedImage

_filePath

protected java.lang.String _filePath

_pixels

protected java.lang.Object _pixels

_pixelsInBytes

protected byte[] _pixelsInBytes

_pixelsInShort

protected short[] _pixelsInShort

_pixelsInInt

protected int[] _pixelsInInt

_rasta

protected java.awt.image.WritableRaster _rasta

_dataBuffer

protected java.awt.image.DataBuffer _dataBuffer

_mask

protected int _mask

_roi

protected java.awt.Rectangle _roi

_lineStride

protected int _lineStride
Constructor Detail

SLBufferedImage

public SLBufferedImage(java.lang.String filePath)

SLBufferedImage

public SLBufferedImage(java.lang.String dir,
                       java.lang.String fileName,
                       java.lang.String fileFormat)
Constructor with 3 string arguments.

Parameters:
dir - e.g. "./src/test/resources/images/smallThinShapes";
fileName - e.g. "blobs"
fileFormat - e.g. ".gif"

SLBufferedImage

public SLBufferedImage(java.awt.image.BufferedImage image)
Method Detail

get

public int get(int x,
               int y)
In ImageJ this will return the byte if it is a byte gray else an encoded RGB value.
This does not work well with BufferedImage that has a method to always return the RGB.
I might have to subclass this in order to make an effective implementation.

Specified by:
get in interface SLImage

get

public int get(int index)
Specified by:
get in interface SLImage

getHeight

public int getHeight()
Description copied from interface: SLImage
Returns the height of this image in pixels.

Specified by:
getHeight in interface SLImage

getNChannels

public int getNChannels()
Description copied from interface: SLImage
Returns the number of color channels in the image. The color channels can be accessed by toFloat(channelNumber, fp) and written by setPixels(channelNumber, fp).

Specified by:
getNChannels in interface SLImage
Returns:
1 for grayscale images, 3 for RGB images

getNChannelsOld

public int getNChannelsOld()

getPixelCount

public int getPixelCount()
Specified by:
getPixelCount in interface SLImage

getPixels

public java.lang.Object getPixels()
Description copied from interface: SLImage
Returns a reference to this image's pixel array. The array type (byte[], short[], float[] or int[]) varies depending on the image type.

Specified by:
getPixels in interface SLImage

getPixelsInBytes

public byte[] getPixelsInBytes()

getPixelsInInt

public int[] getPixelsInInt()

getRoi

public java.awt.Rectangle getRoi()
Not implemented for BufferedImage.

Specified by:
getRoi in interface SLImage

getWidth

public int getWidth()
Description copied from interface: SLImage
Returns the width of this image in pixels.

Specified by:
getWidth in interface SLImage

isInvertedLut

public boolean isInvertedLut()
Always false for a BufferedImage.

Specified by:
isInvertedLut in interface SLImage

putPixel

public void putPixel(int x,
                     int y,
                     int value)
Description copied from interface: SLImage
Stores the specified value at (x,y). Does nothing if (x,y) is outside the image boundary. For 8-bit and 16-bit images, out of range values are clipped. For RGB images, the argb values are packed in 'value'. For float images, 'value' is expected to be a float converted to an int using Float.floatToIntBits().

Specified by:
putPixel in interface PixelHandler
Specified by:
putPixel in interface SLImage

set

public void set(int x,
                int y,
                int value)
Description copied from interface: SLImage
This is a faster version of putPixel() that does not clip out of range values and does not do bounds checking.

Specified by:
set in interface SLImage

set

public void set(int index,
                int value)
Specified by:
set in interface SLImage

setPixels

public void setPixels(java.lang.Object pixels)
Description copied from interface: SLImage
Sets a new pixel array for the image. The length of the array must be equal to width*height. Use setSnapshotPixels(null) to clear the snapshot buffer.

Specified by:
setPixels in interface SLImage

setRoi

public void setRoi(java.awt.Rectangle roi)
Specified by:
setRoi in interface SLImage

setRoi

public void setRoi(int x,
                   int y,
                   int rwidth,
                   int rheight)
Specified by:
setRoi in interface SLImage

isEmpty

public boolean isEmpty()
Test for failed image read.
If the read of an image fails it will still create the object but _bufferedImage == null.

Specified by:
isEmpty in interface SLImage

getActiveRectangle

public java.awt.Rectangle getActiveRectangle()
The part of the image that is available in the pixels array.
A hook to only have part of the image active at the same time.
Returning null mean that the whole images is available in the pixels array.

Specified by:
getActiveRectangle in interface SLImage

getLineStride

public int getLineStride()
Number of index position in the pixels array to jump to get to the next line.

Specified by:
getLineStride in interface SLImage

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()

isGray

public boolean isGray()
Specified by:
isGray in interface SLImage

isRgb

public boolean isRgb()
Specified by:
isRgb in interface SLImage

isGray8

public boolean isGray8()
Specified by:
isGray8 in interface SLImage

isGray16

public boolean isGray16()
Specified by:
isGray16 in interface SLImage


Copyright © 2009. All Rights Reserved.