Class ContourPlot.Pixel
- All Implemented Interfaces:
ContourPlot.PixelBase
- Enclosing class:
ContourPlot
ContourPlot.Img.
A Pixel object stores a position and can be used to get and set values of
an Img. It is NOT the value and changing its position will not change the
image, instead it will reference a different value of the image as the
pixel object is a pointer to a value in the Img's data array.
The Pixel class also provides a set of static methods for color decomposition
and recombination from color channels like argb(int, int, int, int)
or a(int), r(int), g(int), b(int).
- Since:
- 1.0
- Author:
- hageldave
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ContourPlot.ImgImg this pixel belongs toprivate intindex of the value this pixel references -
Constructor Summary
ConstructorsConstructorDescriptionPixel(ContourPlot.Img img, int index) Creates a new Pixel object referencing the value of specified Img at specified index.Pixel(ContourPlot.Img img, int x, int y) Creates a new Pixel object referencing the value of specified Img at specified position. -
Method Summary
Modifier and TypeMethodDescriptioninta()final inta(int color) doubleReturns the alpha value of this pixel at its current position.final doublea_normalized(int color) final intargb(int a, int r, int g, int b) Packs 8bit ARGB color components into a single 32bit integer value.final intargb_bounded(int a, int r, int g, int b) Packs 8bit ARGB color components into a single 32bit integer value.final intargb_fast(int a, int r, int g, int b) Packs 8bit ARGB color components into a single 32bit integer value.final intargb_fromNormalized(double a, double r, double g, double b) Packs normalized ARGB color components (values in [0.0 .. 1.0]) into a single 32bit integer value.intb()final intb(int color) doubleReturns the blue value of this pixel at its current position.final doubleb_normalized(int color) intg()final intg(int color) doubleReturns the green value of this pixel at its current position.final doubleg_normalized(int color) intgetGrey(int redWeight, int greenWeight, int blueWeight) Calculates the grey value of this pixel using specified weights.final intgetGrey(int color, int redWeight, int greenWeight, int blueWeight) Calculates a grey value from an RGB or ARGB value using specified weights for each R,G and B channel.intgetIndex()Returns this pixel's index.intfinal intgetLuminance(int color) Returns the underlying image of this pixel (the image referenced by this pixel)intgetValue()Gets the value of the Img at the position currently referenced by this Pixel.intgetX()intgetY()intr()final intr(int color) doubleReturns the red value of this pixel at its current position.final doubler_normalized(int color) final intrgb(int r, int g, int b) Packs 8bit RGB color components into a single 32bit ARGB integer value with alpha=255 (opaque).final intrgb_bounded(int r, int g, int b) Packs 8bit RGB color components into a single 32bit ARGB integer value with alpha=255 (opaque).final intrgb_fast(int r, int g, int b) Packs 8bit RGB color components into a single 32bit ARGB integer value with alpha=255 (opaque).final intrgb_fromNormalized(double r, double g, double b) Packs normalized ARGB color components (values in [0.0 .. 1.0]) into a single 32bit integer value with alpha=255 (opaque).setA(int a) Sets alpha channel value of this Pixel.setA_fromDouble(double a) Sets the alpha value of this pixel at its current position with 0.0 as fully transparent and 1.0 as fully opaque.voidsetARGB(int a, int r, int g, int b) Sets an ARGB value at the position currently referenced by this Pixel.setARGB_fromDouble(double a, double r, double g, double b) Sets an ARGB value at the position currently referenced by this Pixel.setB(int b) Sets blue channel value of this Pixel.setB_fromDouble(double b) Sets the blue value of this pixel at its current position with 0.0 as no blue contribution and 1.0 as full blue contribution.setG(int g) Sets green channel value of this Pixel.setG_fromDouble(double g) Sets the green value of this pixel at its current position with 0.0 as no green contribution and 1.0 as full green contribution.setIndex(int index) Sets the index of the Img value this Pixel references.setPosition(int x, int y) Sets the position of the Img value this Pixel references.setR(int r) Sets red channel value of this Pixel.setR_fromDouble(double r) Sets the red value of this pixel at its current position with 0.0 as no red contribution and 1.0 as full red contribution.voidsetRGB(int r, int g, int b) Sets an opaque RGB value at the position currently referenced by this Pixel.setRGB_fromDouble(double r, double g, double b) Sets an opaque RGB value at the position currently referenced by this Pixel.setRGB_fromDouble_preserveAlpha(double r, double g, double b) Sets an RGB value at the position currently referenced by this Pixel.voidsetRGB_preserveAlpha(int r, int g, int b) Sets an RGB value at the position currently referenced by this Pixel.setValue(int pixelValue) Sets the value of the Img at the position currently referenced by this Pixel.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface gov.nih.mipav.model.algorithms.ContourPlot.PixelBase
asString, getXnormalized, getYnormalized
-
Field Details
-
img
Img this pixel belongs to- Since:
- 1.0
-
index
private int indexindex of the value this pixel references- Since:
- 1.0
-
-
Constructor Details
-
Pixel
Creates a new Pixel object referencing the value of specified Img at specified index.No bounds checks are performed for index.
- Parameters:
img- the Img this pixel corresponds toindex- of the value in the images data array- Since:
- 1.0
- See Also:
-
Pixel
Creates a new Pixel object referencing the value of specified Img at specified position.No bounds checks are performed for x and y
- Parameters:
img- the Img this pixel corresponds tox- coordinatey- coordinate- Since:
- 1.0
- See Also:
-
-
Method Details
-
getSource
Description copied from interface:ContourPlot.PixelBaseReturns the underlying image of this pixel (the image referenced by this pixel)- Specified by:
getSourcein interfaceContourPlot.PixelBase- Returns:
- the Img this Pixel belongs to.
- Since:
- 1.0
- See Also:
-
setIndex
Sets the index of the Img value this Pixel references. No bounds checks are performed.- Specified by:
setIndexin interfaceContourPlot.PixelBase- Parameters:
index- corresponding to the position of the image's data array.- Returns:
- this pixel for chaining
- Since:
- 1.0
- See Also:
-
setPosition
Sets the position of the Img value this Pixel references. No bounds checks are performed.- Specified by:
setPositionin interfaceContourPlot.PixelBase- Parameters:
x- coordinatey- coordinate- Returns:
- this pixel for chaining
- Since:
- 1.0
- See Also:
-
getIndex
public int getIndex()Description copied from interface:ContourPlot.PixelBaseReturns this pixel's index. The index relates to the pixels's position in the following way:
index = y * width + x y = index / width x = index % width- Specified by:
getIndexin interfaceContourPlot.PixelBase- Returns:
- the index of the Img value this Pixel references.
- Since:
- 1.0
- See Also:
-
getX
public int getX()- Specified by:
getXin interfaceContourPlot.PixelBase- Returns:
- the x coordinate of the position in the Img this Pixel references.
- Since:
- 1.0
- See Also:
-
getY
public int getY()- Specified by:
getYin interfaceContourPlot.PixelBase- Returns:
- the y coordinate of the position in the Img this Pixel references.
- Since:
- 1.0
- See Also:
-
setValue
Sets the value of the Img at the position currently referenced by this Pixel.If the position of this pixel is not in bounds of the Img the value for a different position may be set or an ArrayIndexOutOfBoundsException may be thrown.
- Parameters:
pixelValue- to be set e.g. 0xff0000ff for blue.- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
getValue
public int getValue()Gets the value of the Img at the position currently referenced by this Pixel.If the position of this pixel is not in bounds of the Img the value for a different position may be returned or an ArrayIndexOutOfBoundsException may be thrown.
- Returns:
- the value of the Img currently referenced by this Pixel.
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
a
public int a()- Returns:
- the alpha component of the value currently referenced by this Pixel. It is assumed that the value is an ARGB value with 8bits per color channel, so this will return a value in [0..255].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
r
public int r()- Returns:
- the red component of the value currently referenced by this Pixel. It is assumed that the value is an ARGB value with 8bits per color channel, so this will return a value in [0..255].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
g
public int g()- Returns:
- the green component of the value currently referenced by this Pixel. It is assumed that the value is an ARGB value with 8bits per color channel, so this will return a value in [0..255].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
b
public int b()- Returns:
- the blue component of the value currently referenced by this Pixel. It is assumed that the value is an ARGB value with 8bits per color channel, so this will return a value in [0..255].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
a_asDouble
public double a_asDouble()Description copied from interface:ContourPlot.PixelBaseReturns the alpha value of this pixel at its current position. If the underlying image does not support alpha, 1.0 is returned.- Specified by:
a_asDoublein interfaceContourPlot.PixelBase- Returns:
- the normalized alpha component of the value currently referenced by this Pixel. This will return a value in [0.0 .. 1.0].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
r_asDouble
public double r_asDouble()Description copied from interface:ContourPlot.PixelBaseReturns the red value of this pixel at its current position.- Specified by:
r_asDoublein interfaceContourPlot.PixelBase- Returns:
- the normalized red component of the value currently referenced by this Pixel. This will return a value in [0.0 .. 1.0].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
g_asDouble
public double g_asDouble()Description copied from interface:ContourPlot.PixelBaseReturns the green value of this pixel at its current position.- Specified by:
g_asDoublein interfaceContourPlot.PixelBase- Returns:
- the normalized green component of the value currently referenced by this Pixel. This will return a value in [0.0 .. 1.0].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
b_asDouble
public double b_asDouble()Description copied from interface:ContourPlot.PixelBaseReturns the blue value of this pixel at its current position.- Specified by:
b_asDoublein interfaceContourPlot.PixelBase- Returns:
- the normalized blue component of the value currently referenced by this Pixel. This will return a value in [0.0 .. 1.0].
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setARGB
public void setARGB(int a, int r, int g, int b) Sets an ARGB value at the position currently referenced by this Pixel. Each channel value is assumed to be 8bit and otherwise truncated.- Parameters:
a- alphar- redg- greenb- blue- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
setRGB
public void setRGB(int r, int g, int b) Sets an opaque RGB value at the position currently referenced by this Pixel. Each channel value is assumed to be 8bit and otherwise truncated.- Parameters:
r- redg- greenb- blue- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.0
- See Also:
-
setRGB_preserveAlpha
public void setRGB_preserveAlpha(int r, int g, int b) Sets an RGB value at the position currently referenced by this Pixel. The present alpha value will not be altered by this operation. Each channel value is assumed to be 8bit and otherwise truncated.- Parameters:
r- redg- greenb- blue- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setARGB_fromDouble
Sets an ARGB value at the position currently referenced by this Pixel.
Each channel value is assumed to be within [0.0 .. 1.0]. Channel values outside these bounds will be clamped to them.- Specified by:
setARGB_fromDoublein interfaceContourPlot.PixelBase- Parameters:
a- normalized alphar- normalized redg- normalized greenb- normalized blue- Returns:
- this pixel for chaining.
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setRGB_fromDouble
Sets an opaque RGB value at the position currently referenced by this Pixel.
Each channel value is assumed to be within [0.0 .. 1.0]. Channel values outside these bounds will be clamped to them.- Specified by:
setRGB_fromDoublein interfaceContourPlot.PixelBase- Parameters:
r- normalized redg- normalized greenb- normalized blue- Returns:
- this pixel for chaining.
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setRGB_fromDouble_preserveAlpha
Sets an RGB value at the position currently referenced by this Pixel. The present alpha value will not be altered by this operation.
Each channel value is assumed to be within [0.0 .. 1.0]. Channel values outside these bounds will be clamped to them.- Specified by:
setRGB_fromDouble_preserveAlphain interfaceContourPlot.PixelBase- Parameters:
r- normalized redg- normalized greenb- normalized blue- Returns:
- this pixel for chaining.
- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setA
Sets alpha channel value of this Pixel. Value will be truncated to 8bits (e.g. 0x12ff will truncate to 0xff).- Parameters:
a- alpha value in range [0..255]- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setR
Sets red channel value of this Pixel. Value will be truncated to 8bits (e.g. 0x12ff will truncate to 0xff).- Parameters:
r- red value in range [0..255]- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setG
Sets green channel value of this Pixel. Value will be truncated to 8bits (e.g. 0x12ff will truncate to 0xff).- Parameters:
g- green value in range [0..255]- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setB
Sets blue channel value of this Pixel. Value will be truncated to 8bits (e.g. 0x12ff will truncate to 0xff).- Parameters:
b- blue value in range [0..255]- Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
setA_fromDouble
Description copied from interface:ContourPlot.PixelBaseSets the alpha value of this pixel at its current position with 0.0 as fully transparent and 1.0 as fully opaque. If the underlying image does not support alpha, this call imediately returns without modifying the image.- Specified by:
setA_fromDoublein interfaceContourPlot.PixelBase- Parameters:
a- the alpha value. May exceed [0,1] range depending on implementation.- Returns:
- this pixel for chaining.
- See Also:
-
setR_fromDouble
Description copied from interface:ContourPlot.PixelBaseSets the red value of this pixel at its current position with 0.0 as no red contribution and 1.0 as full red contribution.- Specified by:
setR_fromDoublein interfaceContourPlot.PixelBase- Parameters:
r- the red value. May exceed [0,1] range depending on implementation.- Returns:
- this pixel for chaining.
- See Also:
-
setG_fromDouble
Description copied from interface:ContourPlot.PixelBaseSets the green value of this pixel at its current position with 0.0 as no green contribution and 1.0 as full green contribution.- Specified by:
setG_fromDoublein interfaceContourPlot.PixelBase- Parameters:
g- the green value. May exceed [0,1] range depending on implementation.- Returns:
- this pixel for chaining.
- See Also:
-
setB_fromDouble
Description copied from interface:ContourPlot.PixelBaseSets the blue value of this pixel at its current position with 0.0 as no blue contribution and 1.0 as full blue contribution.- Specified by:
setB_fromDoublein interfaceContourPlot.PixelBase- Parameters:
b- the blue value. May exceed [0,1] range depending on implementation.- Returns:
- this pixel for chaining.
- See Also:
-
getLuminance
public int getLuminance()- Returns:
- 8bit luminance value of this pixel.
Using weights r=0.2126 g=0.7152 b=0.0722 - Throws:
ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
getGrey
public int getGrey(int redWeight, int greenWeight, int blueWeight) Calculates the grey value of this pixel using specified weights.- Parameters:
redWeight- weight for red channelgreenWeight- weight for green channelblueWeight- weight for blue channel- Returns:
- grey value of pixel for specified weights
- Throws:
ArithmeticException- divide by zero if the weights sum up to 0.ArrayIndexOutOfBoundsException- if this Pixel's index is not in range of the Img's data array.- Since:
- 1.2
- See Also:
-
toString
-
getLuminance
public final int getLuminance(int color) - Parameters:
color- RGB(24bit) or ARGB(32bit) value- Returns:
- 8bit luminance value of given RGB value.
Using weights r=0.2126 g=0.7152 b=0.0722 - Since:
- 1.0
- See Also:
-
getGrey
public final int getGrey(int color, int redWeight, int greenWeight, int blueWeight) Calculates a grey value from an RGB or ARGB value using specified weights for each R,G and B channel.Weights are integer values so normalized weights need to be converted beforehand. E.g. normalized weights (0.33, 0.62, 0.05) would be have to be converted to integer weights (33, 62, 5).
When using weights with same signs, the value is within [0..255]. When weights have mixed signs the resulting value is unbounded.
- Parameters:
color- RGB(24bit) or ARGB(32bit) valueredWeight- weight for red channelgreenWeight- weight for green channelblueWeight- weight for blue channel- Returns:
- weighted grey value (8bit) of RGB color value for non-negative weights.
- Throws:
ArithmeticException- divide by zero if the weights sum up to 0.- Since:
- 1.0
- See Also:
-
rgb_bounded
public final int rgb_bounded(int r, int g, int b) Packs 8bit RGB color components into a single 32bit ARGB integer value with alpha=255 (opaque). Components are clamped to [0,255].- Parameters:
r- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.0
- See Also:
-
rgb
public final int rgb(int r, int g, int b) Packs 8bit RGB color components into a single 32bit ARGB integer value with alpha=255 (opaque). Components larger than 8bit get truncated to 8bit.- Parameters:
r- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.0
- See Also:
-
rgb_fast
public final int rgb_fast(int r, int g, int b) Packs 8bit RGB color components into a single 32bit ARGB integer value with alpha=255 (opaque). Components larger than 8bit are NOT truncated and will result in a broken, malformed value.- Parameters:
r- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.0
- See Also:
-
rgb_fromNormalized
public final int rgb_fromNormalized(double r, double g, double b) Packs normalized ARGB color components (values in [0.0 .. 1.0]) into a single 32bit integer value with alpha=255 (opaque). Component values less than 0 or greater than 1 clamped to fit the range.- Parameters:
r- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.2
- See Also:
-
argb_bounded
public final int argb_bounded(int a, int r, int g, int b) Packs 8bit ARGB color components into a single 32bit integer value. Components are clamped to [0,255].- Parameters:
a- alphar- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.0
- See Also:
-
argb
public final int argb(int a, int r, int g, int b) Packs 8bit ARGB color components into a single 32bit integer value. Components larger than 8bit get truncated to 8bit.- Parameters:
a- alphar- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.0
- See Also:
-
argb_fast
public final int argb_fast(int a, int r, int g, int b) Packs 8bit ARGB color components into a single 32bit integer value. Components larger than 8bit are NOT truncated and will result in a broken, malformed value.- Parameters:
a- alphar- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.0
- See Also:
-
argb_fromNormalized
public final int argb_fromNormalized(double a, double r, double g, double b) Packs normalized ARGB color components (values in [0.0 .. 1.0]) into a single 32bit integer value. Component values less than 0 or greater than 1 are clamped to fit the range.- Parameters:
a- alphar- redg- greenb- blue- Returns:
- packed ARGB value
- Since:
- 1.2
- See Also:
-
b
public final int b(int color) - Parameters:
color- ARGB(32bit) or RGB(24bit) value- Returns:
- blue component(8bit) of specified color.
- Since:
- 1.0
- See Also:
-
g
public final int g(int color) - Parameters:
color- ARGB(32bit) or RGB(24bit) value- Returns:
- green component(8bit) of specified color.
- Since:
- 1.0
- See Also:
-
r
public final int r(int color) - Parameters:
color- ARGB(32bit) or RGB(24bit) value- Returns:
- red component(8bit) of specified color.
- Since:
- 1.0
- See Also:
-
a
public final int a(int color) - Parameters:
color- ARGB(32bit) value- Returns:
- alpha component(8bit) of specified color.
- Since:
- 1.0
- See Also:
-
b_normalized
public final double b_normalized(int color) - Parameters:
color- ARGB(32bit) or RGB(24bit) value- Returns:
- normalized blue component of specified color
(value in [0.0 .. 1.0]). - Since:
- 1.2
- See Also:
-
g_normalized
public final double g_normalized(int color) - Parameters:
color- ARGB(32bit) or RGB(24bit) value- Returns:
- normalized green component of specified color
(value in [0.0 .. 1.0]). - Since:
- 1.2
- See Also:
-
r_normalized
public final double r_normalized(int color) - Parameters:
color- ARGB(32bit) or RGB(24bit) value- Returns:
- normalized red component of specified color
(value in [0.0 .. 1.0]). - Since:
- 1.2
- See Also:
-
a_normalized
public final double a_normalized(int color) - Parameters:
color- ARGB(32bit) value- Returns:
- normalized alpha component of specified color
(value in [0.0 .. 1.0]). - Since:
- 1.2
- See Also:
-