Normalize color band #250
-
Hi everyone, I'm trying to do a simple normalization of a gray-scale image color-band from negative range to a desired range of 0 to 255 (see code below). code setup /**
* Generate tiles for the object and put them to temporary storage.
*
* @param File $file
* @param string $path Path to the cached image file.
*/
public function generateTiles($file, $path)
{
$vipsImage = VipsImage::newFromFile($path);
$min = $vipsImage->min();
$max = $vipsImage->max();
if($min < 0 || $min > 255 || $max < 0 || $max > 255) {
$vipsImage = $vipsImage->subtract($min)->divide($max - $min)->multiply(255);
$vipsImage->dzsave($this->tempPath, [
'layout' => 'zoomify',
'container' => 'fs',
'strip' => true,
]);
}
} The example images I use are geoTIFF files which have a negative color-band range (e.g. this example .tif with So my question is, how could I get the min-value of the true pixel values of the geoTIFF and disregard the NoData pixel values. Any help to achieve this is greatly appreciated! Thanks in advance for your time and effort. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @mtiessen1175, Do you have a sample image you could share? If you want to find the min and exclude -99999, it's probably easiest to set the -99999s to 0 (or some very high value?) before searching for min. Perhaps (untested): $min = $image->equal(-99999)->ifthenelse(0, $image)->min(); You can speed it up with You could also call |
Beta Was this translation helpful? Give feedback.
Hello @mtiessen1175,
Do you have a sample image you could share?
If you want to find the min and exclude -99999, it's probably easiest to set the -99999s to 0 (or some very high value?) before searching for min. Perhaps (untested):
You can speed it up with
stats()
. This will make a single pass over the image and find max and min together.You could also call
linear()
directly. This computesy = a * x + b
, so you can replace your -, /, * with a single call.