affineNMF image_type

This commit is contained in:
tqlong
2010-06-03 00:06:05 +00:00
parent 99d0cbd6b8
commit 02486944b4
2 changed files with 95 additions and 0 deletions
@@ -0,0 +1,34 @@
#include <fastlib/fastlib.h>
#include "image_type.h"
double ImageType::Difference(const ImageType& image,
double (*kernel)(const PointType&,
const PointType&) ) const {
double s = 0;
for (index_t i = 0; i < pList.size(); i++)
for (index_t j = 0; j < image.pList.size(); j++)
s += kernel(pList[i], image.pList[j]);
return s;
}
double exp_kernel(const PointType& p1, const PointType& p2) {
double sigma2 = 1;
double s = (p1.r-p2.r)*(p1.r-p2.r) + (p1.c-p2.c)*(p1.c-p2.c);
return exp(-0.5/sigma2*s) * (p1.f-p2.f)*(p1.f-p2.f);
}
void ImageType::Scale(ImageType& image_out, double s) {
image_out.pList.Renew();
image_out.pList.InitCopy(pList);
for (index_t i = 0; i < pList.size(); i++)
image_out.pList[i].f *= s;
}
void ImageType::Transform(ImageType& image_out,
const Transformation& t, double s) {
image_out.pList.Renew();
image_out.pList.Init(pList.size());
for (index_t i = 0; i < pList.size(); i++)
image_out.pList[i] = pList[i].Transform(t, s);
}
@@ -0,0 +1,61 @@
#pragma once
/** image_type.h
**/
struct Transformation {
Vector m;
Transformation() {
m.Init(8);
m[0] = 1; m[1] = 0; m[2] = 0;
m[3] = 0; m[4] = 1; m[5] = 0;
m[6] = 0; m[7] = 0;
}
Transformation(const Transformation& t) {
m.Copy(t.m);
}
};
struct PointType {
double r; // row
double c; // col
double f; // feature value or intensity
PointType Transform(const Transformation& t, double s = 1.0) const {
PointType newPoint;
double d = t.m[6]*r + t.m[7]*c + 1;
newPoint.r = (t.m[0]*r + t.m[1]*c + t.m[2])/d;
newPoint.c = (t.m[3]*r + t.m[4]*c + t.m[5])/d;
newPoint.f = f * s;
return newPoint;
}
};
double exp_kernel(const PointType&, const PointType&);
struct ImageType {
ArrayList<PointType> pList;
// Members
ImageType() {
pList.Init();
}
ImageType(const ImageType& image) {
pList.InitCopy(image.pList);
}
void Add(const ImageType& image) {
pList.AppendCopy(image.pList);
}
double Difference(const ImageType& image,
double (*kernel)(const PointType&,
const PointType&) = exp_kernel) const;
void Scale(ImageType& image_out, double s = 1.0);
void Transform(ImageType& image_out, const Transformation& t, double s = 1.0);
};