Package org.robwork.sdurw_sensor
Class Image
- java.lang.Object
-
- org.robwork.sdurw_sensor.Image
-
public class Image extends java.lang.Object
The image class is a simple wrapper around a char data array.
This Image wrapper contain information of width, height and encoding.
The image class is somewhat inspired by the IplImage of opencv.
The coordinate system has its origin located at the top-left position, where from X increases
to the left and Y-increases downwards.
setting pixel values in an efficient manner has been enabled using some template joggling.
It requires that the user know what type of image he/she is working with.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Image.ColorCode
The color encodings that the image can use.static class
Image.Pixel4i
static class
Image.PixelDepth
The pixeldepth determines how many bits that are used per pixel per channel
-
Constructor Summary
Constructors Constructor Description Image()
default constructorImage(long cPtr, boolean cMemoryOwn)
Image(long width, long height, Image.ColorCode encoding, Image.PixelDepth depth)
constructorImage(java.lang.String imgData, long width, long height, Image.ColorCode encoding, Image.PixelDepth depth)
constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ImagePtr
copyFlip(boolean horizontal, boolean vertical)
copies this image and flips it around horizontal or vertical axis or both.void
delete()
long
getBitsPerPixel()
returns the number of bits per pixel.Image.ColorCode
getColorEncoding()
returns color encoding/type of this imagestatic long
getCPtr(Image obj)
long
getDataSize()
returns the size of the char data arraylong
getHeight()
returns the height of this imagejava.lang.String
getImageData()
returns a char pointer to the image datapair_ui_ui
getImageDimension()
returns the dimensions (width and height) of this imagelong
getNrOfChannels()
The number of channels that this image has.Pixel4f
getPixel(long x, long y)
generic but inefficient access to pixel information.void
getPixel(long x, long y, Image.Pixel4i dst)
generic access to pixel information, however user must take care of the pixel
depth himself.void
getPixel(long x, long y, Pixel4f dst)
generic but inefficient access to pixel information.Image.PixelDepth
getPixelDepth()
bits per pixel encoded as a PixelDepth type.Pixel4f
getPixelf(long x, long y)
Image.Pixel4i
getPixeli(long x, long y)
generic access to pixel information, however user must take care of the pixel
depth himself.float
getPixelValue(long x, long y, long channel)
generic but inefficient access to a specific channel of
a pixel.float
getPixelValuef(long x, long y, long channel)
int
getPixelValuei(long x, long y, long channel)
long
getWidth()
returns the width of this imagelong
getWidthStep()
the size of an aligned image row in bytes.void
resize(long width, long height)
resizes the current image.boolean
saveAsPGM(java.lang.String fileName)
saves this image to a file in the PGM (grayscale) formatboolean
saveAsPGMAscii(java.lang.String fileName)
saves this image to a file in the ascii PGM (grayscale) formatboolean
saveAsPPM(java.lang.String fileName)
saves this image to a file in the PPM (color) formatvoid
setImageData(java.lang.String data)
sets the data array of this image.void
setPixel(long x, long y, Pixel4f value)
void
setPixel16S(int x, int y, SWIGTYPE_p_int16_t value)
void
setPixel16S(int x, int y, SWIGTYPE_p_int16_t ch0, SWIGTYPE_p_int16_t ch1, SWIGTYPE_p_int16_t ch2)
void
setPixel16S(int x, int y, SWIGTYPE_p_int16_t ch0, SWIGTYPE_p_int16_t ch1, SWIGTYPE_p_int16_t ch2, SWIGTYPE_p_int16_t ch3)
void
setPixel16U(int x, int y, int value)
void
setPixel16U(int x, int y, int ch0, int ch1, int ch2)
void
setPixel16U(int x, int y, int ch0, int ch1, int ch2, int ch3)
void
setPixel32F(int x, int y, float value)
void
setPixel32F(int x, int y, float ch0, float ch1, float ch2)
void
setPixel32F(int x, int y, float ch0, float ch1, float ch2, float ch3)
void
setPixel32S(int x, int y, SWIGTYPE_p_int32_t value)
void
setPixel32S(int x, int y, SWIGTYPE_p_int32_t ch0, SWIGTYPE_p_int32_t ch1, SWIGTYPE_p_int32_t ch2)
void
setPixel32S(int x, int y, SWIGTYPE_p_int32_t ch0, SWIGTYPE_p_int32_t ch1, SWIGTYPE_p_int32_t ch2, SWIGTYPE_p_int32_t ch3)
void
setPixel8S(int x, int y, SWIGTYPE_p_int8_t value)
void
setPixel8S(int x, int y, SWIGTYPE_p_int8_t ch0, SWIGTYPE_p_int8_t ch1, SWIGTYPE_p_int8_t ch2)
void
setPixel8S(int x, int y, SWIGTYPE_p_int8_t ch0, SWIGTYPE_p_int8_t ch1, SWIGTYPE_p_int8_t ch2, SWIGTYPE_p_int8_t ch3)
void
setPixel8U(int x, int y, short value)
sets the gray tone in a 1-channel gray tone image withvoid
setPixel8U(int x, int y, short ch0, short ch1, short ch2)
void
setPixel8U(int x, int y, short ch0, short ch1, short ch2, short ch3)
-
-
-
Constructor Detail
-
Image
public Image(long cPtr, boolean cMemoryOwn)
-
Image
public Image()
default constructor
-
Image
public Image(long width, long height, Image.ColorCode encoding, Image.PixelDepth depth)
constructor- Parameters:
width
- [in] width of the imageheight
- [in] height of the imageencoding
- [in] the colorCode of this Imagedepth
- [in] the pixel depth in bits per channel
-
Image
public Image(java.lang.String imgData, long width, long height, Image.ColorCode encoding, Image.PixelDepth depth)
constructor- Parameters:
imgData
- [in] char pointer that points to an array of chars with
length width*height*(bitsPerPixel/8)width
- [in] width of the imageheight
- [in] height of the imageencoding
- [in] the colorCode of this Imagedepth
- [in] the pixel depth in bits per channel
-
-
Method Detail
-
getCPtr
public static long getCPtr(Image obj)
-
delete
public void delete()
-
resize
public void resize(long width, long height)
resizes the current image.- Parameters:
width
- [in] width in pixelsheight
- [in] height in pixels
-
getImageData
public java.lang.String getImageData()
returns a char pointer to the image data- Returns:
- char pointer to the image data
-
setImageData
public void setImageData(java.lang.String data)
sets the data array of this image. Make sure to
change the height and width accordingly.
-
getDataSize
public long getDataSize()
returns the size of the char data array- Returns:
- size of char data array
-
getImageDimension
public pair_ui_ui getImageDimension()
returns the dimensions (width and height) of this image- Returns:
- a pair of integers where first is the width and second
is the height
-
getWidth
public long getWidth()
returns the width of this image- Returns:
- image width
-
getHeight
public long getHeight()
returns the height of this image- Returns:
- image height
-
getColorEncoding
public Image.ColorCode getColorEncoding()
returns color encoding/type of this image- Returns:
- ColorCode of this image
-
getBitsPerPixel
public long getBitsPerPixel()
returns the number of bits per pixel. This is the number
of bits used per pixel per channel.- Returns:
- number of bits per pixel
-
saveAsPGM
public boolean saveAsPGM(java.lang.String fileName)
saves this image to a file in the PGM (grayscale) format- Parameters:
fileName
- [in] the name of the file that is to be created
- Returns:
- true if save was succesfull, false otherwise
-
saveAsPGMAscii
public boolean saveAsPGMAscii(java.lang.String fileName)
saves this image to a file in the ascii PGM (grayscale) format- Parameters:
fileName
- [in] the name of the file that is to be created- Returns:
- true if save was succesfull, false otherwise
-
saveAsPPM
public boolean saveAsPPM(java.lang.String fileName)
saves this image to a file in the PPM (color) format- Parameters:
fileName
- [in] the name of the file that is to be created- Returns:
- true if save was succesfull, false otherwise
-
getWidthStep
public long getWidthStep()
the size of an aligned image row in bytes. This may not be
the same as the width if extra bytes are padded to each row for
alignment purposes.- Returns:
- size of aligned image row
-
getPixelDepth
public Image.PixelDepth getPixelDepth()
bits per pixel encoded as a PixelDepth type.- Returns:
- the pixel depth
-
getNrOfChannels
public long getNrOfChannels()
The number of channels that this image has.- Returns:
- nr of channels
-
getPixel
public Pixel4f getPixel(long x, long y)
generic but inefficient access to pixel information. The float
value is between [0;1] which means non float images are scaled according to
their pixel depth (bits per pixel).- Parameters:
x
- [in] x coordinatey
- [in] y coordinate- Returns:
- up to 4 pixels (depends on nr of channels) in a float format
-
getPixelf
public Pixel4f getPixelf(long x, long y)
-
getPixel
public void getPixel(long x, long y, Pixel4f dst)
generic but inefficient access to pixel information. The float
value is between [0;1] which means non float images are scaled according to
their pixel depth (bits per pixel).- Parameters:
x
- [in] x coordinatey
- [in] y coordinatedst
- [out] up to 4 pixels (depends on nr of channels) in a float format
-
getPixeli
public Image.Pixel4i getPixeli(long x, long y)
generic access to pixel information, however user must take care of the pixel
depth himself. If image is a Depth8U then the maximum value is 254. Also float images
are scaled accordingly.- Parameters:
x
- [in] x coordinatey
- [in] y coordinate- Returns:
- up to 4 pixels (depends on nr of channels) as ints
-
getPixel
public void getPixel(long x, long y, Image.Pixel4i dst)
generic access to pixel information, however user must take care of the pixel
depth himself. If image is a Depth8U then the maximum value is 254. Also float images
are scaled accordingly.- Parameters:
x
- [in] x coordinatey
- [in] y coordinatedst
- [out] up to 4 pixels (depends on nr of channels) in a float format
-
getPixelValue
public float getPixelValue(long x, long y, long channel)
generic but inefficient access to a specific channel of
a pixel.- Parameters:
x
- [in]y
- [in]channel
- documentation missing !- Returns:
- the pixel value.
-
getPixelValuef
public float getPixelValuef(long x, long y, long channel)
-
getPixelValuei
public int getPixelValuei(long x, long y, long channel)
-
setPixel
public void setPixel(long x, long y, Pixel4f value)
-
setPixel8U
public void setPixel8U(int x, int y, short value)
sets the gray tone in a 1-channel gray tone image with- Parameters:
x
-y
-value
-
-
setPixel8U
public void setPixel8U(int x, int y, short ch0, short ch1, short ch2)
-
setPixel8U
public void setPixel8U(int x, int y, short ch0, short ch1, short ch2, short ch3)
-
setPixel8S
public void setPixel8S(int x, int y, SWIGTYPE_p_int8_t value)
-
setPixel8S
public void setPixel8S(int x, int y, SWIGTYPE_p_int8_t ch0, SWIGTYPE_p_int8_t ch1, SWIGTYPE_p_int8_t ch2)
-
setPixel8S
public void setPixel8S(int x, int y, SWIGTYPE_p_int8_t ch0, SWIGTYPE_p_int8_t ch1, SWIGTYPE_p_int8_t ch2, SWIGTYPE_p_int8_t ch3)
-
setPixel16U
public void setPixel16U(int x, int y, int value)
-
setPixel16U
public void setPixel16U(int x, int y, int ch0, int ch1, int ch2)
-
setPixel16U
public void setPixel16U(int x, int y, int ch0, int ch1, int ch2, int ch3)
-
setPixel16S
public void setPixel16S(int x, int y, SWIGTYPE_p_int16_t value)
-
setPixel16S
public void setPixel16S(int x, int y, SWIGTYPE_p_int16_t ch0, SWIGTYPE_p_int16_t ch1, SWIGTYPE_p_int16_t ch2)
-
setPixel16S
public void setPixel16S(int x, int y, SWIGTYPE_p_int16_t ch0, SWIGTYPE_p_int16_t ch1, SWIGTYPE_p_int16_t ch2, SWIGTYPE_p_int16_t ch3)
-
setPixel32S
public void setPixel32S(int x, int y, SWIGTYPE_p_int32_t value)
-
setPixel32S
public void setPixel32S(int x, int y, SWIGTYPE_p_int32_t ch0, SWIGTYPE_p_int32_t ch1, SWIGTYPE_p_int32_t ch2)
-
setPixel32S
public void setPixel32S(int x, int y, SWIGTYPE_p_int32_t ch0, SWIGTYPE_p_int32_t ch1, SWIGTYPE_p_int32_t ch2, SWIGTYPE_p_int32_t ch3)
-
setPixel32F
public void setPixel32F(int x, int y, float value)
-
setPixel32F
public void setPixel32F(int x, int y, float ch0, float ch1, float ch2)
-
setPixel32F
public void setPixel32F(int x, int y, float ch0, float ch1, float ch2, float ch3)
-
copyFlip
public ImagePtr copyFlip(boolean horizontal, boolean vertical)
copies this image and flips it around horizontal or vertical axis or both.- Returns:
- new image.
-
-