public class Utils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
average(int argb0,
int argb1)
Averages two ARGB colors.
|
static int |
clabToRGB(float[] clab)
Converts an CLAB value to a RGB color value.
|
static String |
clabToString(float[] clab)
Returns a string representation of a CLAB value.
|
static float |
colordiff(int rgb0,
int rgb1)
Computes Euclidian distance of two RGB color values.
|
static float |
colordiffsq(int rgb0,
int rgb1)
Computes squared euclidian distance of two RGB color values.
|
static void |
dilate(float[] cm,
int xres,
int yres)
Applies the morphological dilate operator.
|
static void |
erode(float[] cm,
int xres,
int yres)
Applies the morphological erode operator.
|
static float |
euclid(float[] p,
float[] q)
Euclidian distance of p and q.
|
static int |
getAlpha(int argb)
Returns the alpha component of an ARGB value.
|
static int |
getBlue(int rgb)
Returns the blue component of an (A)RGB value.
|
static int |
getGreen(int rgb)
Returns the green component of an (A)RGB value.
|
static int |
getRed(int rgb)
Returns the red component of an (A)RGB value.
|
static float |
labcolordiff(int rgb0,
int rgb1)
Computes squared euclidian distance in CLAB space for two colors
given as RGB values.
|
static float |
labcolordiffsq(int rgb0,
int rgb1)
Computes squared euclidian distance in CLAB space for two colors
given as RGB values.
|
static void |
normalizeMatrix(float[] cm)
Normalizes the matrix to values to [0..1].
|
static int |
packPixel(int a,
int r,
int g,
int b)
Limits the values of a,r,g,b to values from 0 to 255 and puts them
together into an 32 bit integer.
|
static void |
premultiplyMatrix(float alpha,
float[] cm)
Multiplies matrix with the given scalar.
|
static float[] |
rgbToClab(int rgb)
Converts 24-bit RGB values to {l,a,b} float values.
|
static int |
setAlpha(float alpha,
int rgb)
Sets the alpha byte of a pixel.
|
static int |
setAlpha(int alpha,
int rgb)
Sets the alpha byte of a pixel.
|
static void |
smoothcm(float[] cm,
int xres,
int yres,
float f1,
float f2,
float f3)
Blurs confidence matrix with a given symmetrically weighted kernel.
|
static float |
sqrEuclidianDist(float[] p,
float[] q)
Squared Euclidian distance of p and q.
|
public static void dilate(float[] cm, int xres, int yres)
cm
- Confidence matrix to be processed.xres
- Horizontal resolution of the matrix.yres
- Vertical resolution of the matrix.public static void erode(float[] cm, int xres, int yres)
cm
- Confidence matrix to be processed.xres
- Horizontal resolution of the matrix.yres
- Vertical resolution of the matrix.public static void normalizeMatrix(float[] cm)
cm
- The matrix to be normalized.public static void premultiplyMatrix(float alpha, float[] cm)
alpha
- The scalar value.cm
- The matrix of values be multiplied with alpha.public static void smoothcm(float[] cm, int xres, int yres, float f1, float f2, float f3)
In the standard case confidence matrix entries are between 0...1 and the weight factors sum up to 1.
cm
- The matrix to be smoothed.xres
- Horizontal resolution of the matrix.yres
- Vertical resolution of the matrix.f1
- Weight factor for the first pixel.f2
- Weight factor for the mid-pixel.f3
- Weight factor for the last pixel.public static float sqrEuclidianDist(float[] p, float[] q)
Usage hint: When only comparisons between Euclidian distances without actual values are needed, the squared distance can be preferred for being faster to compute.
p
- First euclidian point coordinates.q
- Second euclidian point coordinates.
Dimension must not be smaller than that of p.
Any extra dimensions will be ignored.euclid(float[], float[])
public static float euclid(float[] p, float[] q)
p
- First euclidian point coordinates.q
- Second euclidian point coordinates.
Dimension must not be smaller than that of p.
Any extra dimensions will be ignored.sqrEuclidianDist(float[], float[])
public static float colordiff(int rgb0, int rgb1)
rgb0
- First color value.rgb1
- Second color value.public static float colordiffsq(int rgb0, int rgb1)
Note: Faster to compute than colordiff
rgb0
- First color value.rgb1
- Second color value.public static int average(int argb0, int argb1)
argb0
- First color value.argb1
- Second color value.public static float labcolordiffsq(int rgb0, int rgb1)
rgb0
- First color value.rgb1
- Second color value.public static float labcolordiff(int rgb0, int rgb1)
rgb0
- First color value.rgb1
- Second color value.public static float[] rgbToClab(int rgb)
The conversion used is decribed at CLAB Conversion for reference white D65. Note that the conversion is computational expensive. Results are cached to speed up further conversion calls.
rgb
- RGB color value,public static int clabToRGB(float[] clab)
This is the reverse operation to rgbToClab.
clab
- CLAB value.rgbToClab(int)
public static int setAlpha(int alpha, int rgb)
alpha
- Alpha value from 0 (transparent) to 255 (opaque).rgb
- The 24bit rgb color to be combined with the alpga value.public static int setAlpha(float alpha, int rgb)
alpha
- Alpha value from 0.0f (transparent) to 1.0f (opaque).rgb
- The 24bit rgb color to be combined with the alpga value.public static int packPixel(int a, int r, int g, int b)
a
- Alpha part, the first byte.r
- Red part, the second byte.g
- Green part, the third byte.b
- Blue part, the fourth byte.public static int getAlpha(int argb)
argb
- An ARGB color value.public static int getRed(int rgb)
rgb
- An (A)RGB color value.public static int getGreen(int rgb)
rgb
- An (A)RGB color value.public static int getBlue(int rgb)
rgb
- An (A)RGB color value.public static String clabToString(float[] clab)
clab
- The CLAB value.Copyright © 2015–2021 Fiji. All rights reserved.