18 #ifndef PIC_FEATURES_MATCHING_WARD_ALIGNMENT_HPP 19 #define PIC_FEATURES_MATCHING_WARD_ALIGNMENT_HPP 23 #include "../image.hpp" 24 #include "../util/vec.hpp" 25 #include "../util/string.hpp" 26 #include "../image_samplers/image_sampler_bilinear.hpp" 27 #include "../filtering/filter_downsampler_2d.hpp" 28 #include "../filtering/filter_luminance.hpp" 54 for(
unsigned int i=0; i<
luminance.size(); i++) {
58 for(
unsigned int i=0; i<
img1_v.size(); i++) {
62 for(
unsigned int i=0; i<
img2_v.size(); i++) {
66 for(
unsigned int i=0; i<
tb1_v.size(); i++) {
70 for(
unsigned int i=0; i<
tb2_v.size(); i++) {
90 if(percentile < 0.0f && percentile > 1.0f) {
110 bool bDelete = (L == NULL);
121 bool *maskThr =
new bool[n * 2];
122 bool *maskEb = &maskThr[n];
125 float medVal = ret[0];
130 for(
int i = 0; i < n; i++) {
131 maskThr[i] = L->
data[i] > medVal;
132 maskEb[i] = !((L->
data[i] >= A) && (L->
data[i] <= B));
152 if(img1 == NULL || img2 == NULL) {
177 if(min_coord < (1 << shift_bits)) {
178 shift_bits =
MAX(
log2(min_coord) - 1, 1);
181 Vec2i cur_shift, ret_shift;
183 cur_shift =
Vec2i(0, 0);
184 ret_shift =
Vec2i(0, 0);
189 for(
int i = 0; i < shift_bits; i++) {
193 img1_v.push_back(sml_img1);
194 img2_v.push_back(sml_img2);
201 while(shift_bits > 0) {
205 int width = sml_img1->
width;
206 int height = sml_img1->
height;
207 int n = width * height;
210 bool *tb1 =
MTB(sml_img1, NULL);
213 bool *tb2 =
MTB(sml_img2, NULL);
217 tb1_v.push_back(tb1);
218 tb2_v.push_back(tb2);
222 bool *tb2_shifted =
new bool[n];
223 bool *eb2_shifted =
new bool[n];
228 for(
int i = -1; i <= 1; i++) {
230 for(
int j = -1; j <= 1; j++) {
232 int xs = cur_shift[0] + i;
233 int ys = cur_shift[1] + j;
239 for(
int k=0; k<n; k++) {
240 bool diff_b = tb1[k] ^ tb2_shifted[k];
241 diff_b = diff_b & eb1[k];
242 diff_b = diff_b & eb2_shifted[k];
259 cur_shift[0] = ret_shift[0] * 2;
260 cur_shift[1] = ret_shift[1] * 2;
271 if(imgTarget == NULL || imgSource == NULL) {
293 if(!ret->isSimilarType(img)) {
317 shift =
execute(imgTarget, imgSource);
319 if(shift[0] != 0 && shift[1] != 0) {
static Vec2i execute(Image *imgTarget, Image *imgSource)
Definition: ward_alignment.hpp:266
float percentile
Definition: ward_alignment.hpp:38
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
PIC_INLINE int log2(int n)
log2 computes logarithm in base 2 for integers.
Definition: math.hpp:302
void setZero()
setZero sets data to 0.0f.
int channels
Definition: image.hpp:80
Definition: filter_luminance.hpp:28
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
bool isSimilarType(const Image *img)
isSimilarType checks if the current image is similar to img; i.e. if they have the same width...
int frames
Definition: image.hpp:80
static T * shift(T *bufferOut, T *bufferIn, int dx, int dy, int width, int height, int channels, int frames)
shift
Definition: buffer.hpp:566
std::vector< bool *> eb2_shifted_v
Definition: ward_alignment.hpp:42
Vec< 2, int > Vec2i
Vec2i.
Definition: vec.hpp:829
ImageVec img1_v
Definition: ward_alignment.hpp:41
WardAlignment()
WardAlignment.
Definition: ward_alignment.hpp:47
std::vector< bool *> tb2_v
Definition: ward_alignment.hpp:42
std::vector< bool *> tb2_shifted_v
Definition: ward_alignment.hpp:42
static Image * execute(Image *imgIn, Image *imgOut, int width, int height)
execute
Definition: filter_downsampler_2d.hpp:100
int nPixels() const
nPixels computes the number of pixels.
Definition: image.hpp:499
ImageVec luminance
Definition: ward_alignment.hpp:41
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
std::vector< bool *> tb1_v
Definition: ward_alignment.hpp:42
static Image * execute(Image *imgTarget, Image *imgSource, Vec2i &shift)
execute aligns imgSource to imgTarget
Definition: ward_alignment.hpp:315
The WardAlignment class.
Definition: ward_alignment.hpp:35
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
float tolerance
Definition: ward_alignment.hpp:38
Image * allocateSimilarOne()
allocateSimilarOne creates an Image with similar size of the calling instance.
float * getPercentileVal(float percentile, BBox *box, float *ret)
getPercentileVal computes the n-th value given a percentile.
Definition: bilateral_separation.hpp:25
ImageVec img2_v
Definition: ward_alignment.hpp:41
void update(float percentile, float tolerance)
update sets parameters up for MTB
Definition: ward_alignment.hpp:88
#define MAX(a, b)
Definition: math.hpp:73
static Image * shiftImage(Image *img, Vec2i shift, Image *ret=NULL)
Definition: ward_alignment.hpp:284
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
The Vec class.
Definition: vec.hpp:35
~WardAlignment()
Definition: ward_alignment.hpp:52
bool * MTB(Image *img, Image *L)
MTB computes the median threshold mask.
Definition: ward_alignment.hpp:108
Vec2i getExpShift(Image *img1, Image *img2, int shift_bits=6)
getExpShift computes the shift vector for moving an img1 onto img2
Definition: ward_alignment.hpp:149