Skip to content
Snippets Groups Projects
Commit f58a5d56 authored by Mathieu Westphal (Kitware)'s avatar Mathieu Westphal (Kitware) :zap:
Browse files

vtkImageSSIM: Fix an issue with mode logic

Rework vtkImageSSIM mode logic to separate an explicit automatic mode (default)
from a new MODE_INPUT_RANGE. MODE_NONE has been removed.
parent fa3ac4a4
No related branches found
No related tags found
No related merge requests found
......@@ -261,6 +261,17 @@ vtkImageSSIM::vtkImageSSIM()
this->SetNumberOfOutputPorts(1);
}
//------------------------------------------------------------------------------
void vtkImageSSIM::SetInputToAdditiveChar(unsigned int size)
{
this->C.resize(size);
for (unsigned int i = 0; i < size; ++i)
{
this->C[i][0] = 6.5025;
this->C[i][1] = 58.5225;
}
}
//------------------------------------------------------------------------------
void vtkImageSSIM::GrowExtent(int* uExt, int* wholeExtent)
{
......@@ -327,18 +338,23 @@ void vtkImageSSIM::SetInputToLab()
}
}
//------------------------------------------------------------------------------
void vtkImageSSIM::SetInputToRGBA()
{
if (this->Mode != MODE_RGBA)
{
this->SetInputToAdditiveChar(4);
this->Mode = MODE_RGBA;
this->Modified();
}
}
//------------------------------------------------------------------------------
void vtkImageSSIM::SetInputToRGB()
{
if (this->Mode != MODE_RGB)
{
this->C.resize(3);
for (int i = 0; i < 3; ++i)
{
this->C[i][0] = 6.5025;
this->C[i][1] = 58.5225;
}
this->SetInputToAdditiveChar(3);
this->Mode = MODE_RGB;
this->Modified();
}
......@@ -349,19 +365,26 @@ void vtkImageSSIM::SetInputToGrayscale()
{
if (this->Mode != MODE_GRAYSCALE)
{
this->C.resize(1);
this->C[0][0] = 6.5025;
this->C[0][1] = 58.5225;
this->SetInputToAdditiveChar(1);
this->Mode = MODE_GRAYSCALE;
this->Modified();
}
}
//------------------------------------------------------------------------------
void vtkImageSSIM::SetInputToAuto()
{
if (this->Mode != MODE_AUTO)
{
this->Mode = MODE_AUTO;
this->Modified();
}
}
//------------------------------------------------------------------------------
void vtkImageSSIM::SetInputRange(std::vector<int>& range)
{
if (this->Mode != MODE_NONE)
if (this->Mode != MODE_INPUT_RANGE)
{
this->C.resize(range.size());
for (std::size_t i = 0; i < range.size(); ++i)
......@@ -370,8 +393,8 @@ void vtkImageSSIM::SetInputRange(std::vector<int>& range)
this->C[i][1] = 0.0009 * range[i] * range[i];
}
this->Mode = MODE_INPUT_RANGE;
this->Modified();
this->Mode = MODE_NONE;
}
}
......@@ -402,8 +425,7 @@ int vtkImageSSIM::RequestData(
return 0;
}
// The user hasn't put the right input range
if (C.size() != static_cast<std::size_t>(nComp))
if (this->Mode == MODE_AUTO)
{
C.resize(nComp);
double r[2];
......@@ -416,6 +438,15 @@ int vtkImageSSIM::RequestData(
C[i][1] = 9 * C[i][1];
}
}
else if (C.size() < static_cast<std::size_t>(nComp))
{
vtkLog(ERROR, "Input range is too small for provided input, aborting");
return 0;
}
else if (C.size() > static_cast<std::size_t>(nComp))
{
vtkLog(TRACE, "Input range is bigger than provided input");
}
return this->Superclass::RequestData(request, inputVector, outputVector);
}
......
......@@ -65,12 +65,24 @@ public:
*/
void SetInputToRGB();
/**
* Assume the input is in RGBA format, using integers from 0 to 255.
* This will set appropriate constants c1 and c2 for each input channel
*/
void SetInputToRGBA();
/**
* Assume the input is in grayscale, using integers from 0 to 255.
* This will set appropriate constants c1 and c2
*/
void SetInputToGrayscale();
/**
* The c1 and c2 constant will be computed automatically based on the range of each individual
* components Please note the resulting SSIM can be NaN in specific cases.
*/
void SetInputToAuto();
/**
* Setup the range of each components of the input scalars. If the range has not been set, or if
* the number of components in the input does not match the number of provided ranges,
......@@ -125,7 +137,9 @@ protected:
vtkInformationVector* outputVector) override;
private:
void SetInputToAdditiveChar(unsigned int size);
void GrowExtent(int* uExt, int* wholeExtent);
int PatchRadius = 6;
bool ClampNegativeValues = false;
......@@ -133,10 +147,12 @@ private:
{
MODE_LAB,
MODE_RGB,
MODE_RGBA,
MODE_GRAYSCALE,
MODE_NONE
MODE_AUTO,
MODE_INPUT_RANGE
};
int Mode = MODE_NONE;
int Mode = MODE_AUTO;
/**
* Regularization constants. They are set depending on the range of the input data.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment