norm
, vmain
, vmax
in geomImshow()
¶You can use parameters norm
, vmain
, vmax
when rendering grayscale images.
A grayscale image is specified by 2D array where each element's value represents the luminance of corresponding pixel in the image.
%useLatestDescriptors
%use lets-plot
// Generate 2D arrays.
// First two arrays both contain float numbers but have different range of values.
// The 3rd array contains int-s.
fun linspace(start: Double, end: Double, count: Int): List<Number> {
val step = (end - start) / (count - 1)
return mutableListOf<Double>() +
start + (1 .. (count - 2)).map { i -> start + i * step } + end
}
val arr_f0 = RasterData.create(listOf(linspace(0.3, 0.7, 30)))
val arr_f1 = RasterData.create(listOf(linspace(30.0, 170.0, 30)))
val arr_i = RasterData.create(listOf(linspace(30.0, 170.0, 30).map { it.toInt() }))
// Setup suitable plot options for the demo.
val p = (letsPlot() + ggsize(450, 60) + geomRect(xmin=-0.5, ymin=-0.5, xmax=29.5, ymax=0.5, color="black", alpha=0) +
coordCartesian() + themeClassic() + theme(axis="blank"))
By default, geomImshow()
applies a linear scaling to transform data values to range [0-255].
(p + geomImshow(arr_f0)).show()
(p + geomImshow(arr_f1)).show()
(p + geomImshow(arr_i)).show()
You can disable image normalization using the norm
parameter.
(p + geomImshow(arr_f0, norm=false)).show()
(p + geomImshow(arr_f1, norm=false)).show()
(p + geomImshow(arr_i, norm=false)).show()
vmin, vmax
parameters¶// Set upper limit less than the data max value.
(p + geomImshow(arr_f0, vmax=.5)).show()
(p + geomImshow(arr_f1, vmax=100)).show()
(p + geomImshow(arr_i, vmax=100)).show()
// Set limits wider than the data entire range.
(p + geomImshow(arr_f0, vmin=.4, vmax=.6)).show()
(p + geomImshow(arr_f1, vmin=70, vmax=120)).show()
(p + geomImshow(arr_i, vmin=50, vmax=150)).show()