30#include <vigra/imageinfo.hxx>
31#include <vigra/transformimage.hxx>
32#include <vigra/colorconversions.hxx>
35#include <vigra/resizeimage.hxx>
38#include <vigra/rgbvalue.hxx>
43#define PI 3.14159265358979323846
50 #define snprintf _snprintf
58 template <
class PixelType>
67 template <
class PixelType>
76 template <
class PixelType>
89 typedef typename vigra::NumericTraits<PixelType>::isScalar
srcIsScalar;
138 template <
class PixelType>
157 for (
unsigned int i=0;
i<5;
i++)
166 template <
class PixelType>
171 template <
class PixelType>
175 return std::atan(-(x*x)+
sigma)/
PI + 0.5;
178 return (std::exp(-(x*x)/(2*
sigma*
sigma)) * denom);
211 template <
class PixelType>
213 vigra::RGB2LabFunctor<float>
RGB2Lab;
214 vigra::transformImage(vigra::srcImageRange(*in), vigra::destImage(*
out),
RGB2Lab);
218 template <
class PixelType>
220 vigra::copyImage(srcImageRange(*in), destImage(*
out));
224 template <
class PixelType>
227 vigra::RGBToGrayAccessor<vigra::FRGBImage::PixelType>
color2gray;
228 vigra::FRGBImage
tmpImg(getOutputROI().size());
229 vigra::Point2D offset = vigra::Point2D(info.getPosition());
230 offset -= getOutputROI().upperLeft();
231 if (info.numBands() == 4) {
235 vigra::importImage(info, destImage(
tmpImg, offset));
237 vigra::transformImage(vigra::srcImageRange(
tmpImg,
color2gray), vigra::destImage(*img), log(vigra::functor::Arg1() + vigra::functor::Param(1.0f)));
241 template <
class PixelType>
243 vigra::Point2D offset = vigra::Point2D(info.getPosition());
244 offset -= getOutputROI().upperLeft();
245 if (info.numBands() == 4) {
246 vigra::BImage
imgAlpha(img->size());
249 vigra::importImage(info, destImage(*img, offset));
253 template <
class PixelType>
255 vigra::ImageImportInfo
imgInfo(inputFiles[
i]);
257 weight =
FImagePtr(
new vigra::FImage(getOutputROI().size()));
282 vigra::FindMinMax<float>
minmax;
284 vigra::transformImage(vigra::srcImageRange(*
pInputImg), vigra::destImage(*
pInputImg), vigra::BrightnessContrastFunctor<PixelType>(0.45f, 1.0,
minmax.min,
minmax.max));
300 template <
class PixelType>
302 for (
unsigned int i = 0;
i < inputFiles.size();
i++) {
307 weights.push_back(weight);
314 vigra::exportImage(vigra::srcImageRange(*weight),
exWeights.setPixelType(
"UINT8"));
320 const int origWidth = weights[0]->width();
324 std::vector<ProcessImageTypePtr>
backupLab;
326 for (
unsigned int i = 0;
i < processImages.size();
i++) {
333 std::cout <<
"Running khan algorithm" << std::endl;
338 std::cout <<
"iteration " <<
it+1 << std::endl;
341 std::cout <<
"copying weights from previous iteration" << std::endl;
344 for (
unsigned int i = 0;
i < weights.size();
i++) {
387 FImagePtr tmp(
new vigra::FImage(*weights[
i]));
393 for (
unsigned int i = 0;
i < processImages.size();
i++) {
395 std::cout <<
"processing image " <<
i+1 << std::endl;
403 const int width = processImages[
i]->width();
404 const int height = processImages[
i]->height();
411 vigra::FImage::traverser
wy = weights[
i]->upperLeft();
413 for (
int y=0;
sy.y !=
send.y; ++
sy.y, ++
wy.y, ++y) {
417 vigra::FImage::traverser
wx =
wy;
419 for (
int x=0;
sx.x !=
send.x; ++
sx.x, ++
wx.x, ++x) {
421 std::cout <<
"processing pixel (" << x+1 <<
"," << y+1 <<
")" << std::endl;
426 for (
unsigned int j = 0;
j < processImages.size();
j++) {
428 std::cout <<
"processing layer " <<
j << std::endl;
466 std::cout <<
"(" <<
ndx <<
"," <<
ndy <<
")";
469 if (
ndx != 0 ||
ndy != 0) {
477 std::cout << std::endl;
484 std::cout <<
"computing new weight" << std::endl;
504 std::cout <<
"normalizing weights" << std::endl;
506 for (
unsigned int i=0;
i<weights.size(); ++
i) {
virtual void setVerbosity(int verbosity)
set verbosity level
virtual void setDebugFlags(const uint16_t debugFlags)
set flags for debugging purposes
virtual void setIterationNum(const int iterations)
set number of iterations
virtual void setFlags(const uint16_t flags)
set advanced flags Allows to change behavior of used algorithm
virtual void loadImages(std::vector< std::string > &inputFiles)
load images for processing
std::vector< vigra::ImageImportInfo > inputFiles
Functor to apply mexican hat function returns very small values for input near to 0 or 255.
vigra::BasicImage< vigra::AlgTinyVector< float, 3 > > ProcessImageType
vigra::FRGBImage ImageType
std::shared_ptr< ProcessImageType > ProcessImageTypePtr
std::shared_ptr< ImageType > ImagePtr
vigra::BasicImage< float > ProcessImageType
std::shared_ptr< ImageType > ImagePtr
std::shared_ptr< ProcessImageType > ProcessImageTypePtr
void preprocessImage(unsigned int i, FImagePtr &weight, ProcessImageTypePtr &output)
function to preprocess input image This function loads image, linearize it using EMoR (FIXME),...
ImageTypes< PixelType >::ProcessImageTypePtr ProcessImageTypePtr
vigra::NumericTraits< PixelType >::isScalar srcIsScalar
ImageTypes< PixelType >::ProcessImageType ProcessImageType
std::vector< FImagePtr > weights
ImageTypes< PixelType >::ProcessImageType::PixelType ProcessImagePixelType
virtual std::vector< FImagePtr > createWeightMasks() override
create weight masks create weight masks for masking out ghosting regions
void convertImage(ImageType *in, ProcessImageTypePtr &out, vigra::VigraFalseType)
convert image for internal use if input image is RGB then convert it to L*a*b if input image is grays...
std::vector< ProcessImageTypePtr > processImages
Khan(std::vector< std::string > &inputFiles, const uint16_t flags, const uint16_t debugFlags, int iterations, double sigma, int verbosity)
ImageTypes< PixelType >::ProcessImageType::traverser ProcessImageTraverser
void importRGBImage(vigra::ImageImportInfo &info, ImageType *img, vigra::VigraFalseType)
import RGB image
ImageTypes< PixelType >::ImageType ImageType
float Kh(ProcessImagePixelType x)
transform image using EMoR response
void setSigma(double sigma)
set sigma sets sigma for gaussian weigting function
Fuctor to normalize values.
static uint16_t debugFlags
class AlphaIterator class AlphaAccessor inline void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
vigra::FRGBImage ImageType
#define PI
Header file for Khan's deghosting algorithm Copyright (C) 2009 Lukáš Jirkovský l.jirkovsky@gmail....
Implementation of basic routines for deghosting algorithms Copyright (C) 2009 Lukáš Jirkovský l....
const uint16_t ADV_MULTIRES
std::shared_ptr< vigra::FImage > FImagePtr
const uint16_t SAVE_INITWEIGHTS
Implementation of fast vector type with support of linear algebra operations Copyright (C) 2009 Lukáš...
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.