/* * imgsquare - transform two images until minimum diff is found */ double diff( QImage one, QImage two, int hW, int sW, int vW, int dx, int dy ); int main( int argc, char** argv ) { int hW, sW, vW, r; QString one, two; // FIXME: get these from command line // FIXME: get the two images int dx, dy, ddx, ddy, minDDX, minDDY; dx = dy = ddx = ddy = minDDX = minDDY = 0; double minDiff = -1; double tDiff; for ( ;; ) { for ( ddx = -r ; ddx <= r ; ddx++ ) { for ( ddy = -r ; ddy <= r ; ddy++ ) { tDiff = diff( i1, i2, hW, sW, vW, dx + ddx, dy + ddy ); if ( tDiff == minDiff && ddx*ddx + ddy*ddy < minDDX*minDDX + minDDY*minDDY || tDiff < minDiff || minDiff < 0 ) { minDiff = tDiff; minDDX = ddx; minDDY = ddy; } } } dx += minDDX; dy += minDDY; if ( !minDDX && !minDDY ) break; minDDX = 0; minDDY = 0; minDiff = -1; } // FIXME: all following stuff // make result images, size ( w - abs( dx ), h - abs( dy ) ) // blt from one, origin ( dx > 0 ? dx : 0, dy > 0 ? dy : 0 ) // blt from two, origin ( dx < 0 ? -dx : 0, dy < 0 ? -dy : 0 ) // write images back out } double diff( QImage one, QImage two, int hW, int sW, int vW, int dx, int dy ) { int w, h; // FIXME: image width/height int h1, h2, s1, s2, v1, v2, hD, sD, vD; double d = 0; for( int x = dx ; x + dx < w ; x++ ) { for( int y = dy ; y + dy < h ; y++ ) { // FIXME: get hsv values for one( x, y ) and two( x+dx, y+dy ) hD = abs( h1 - h2 ); if ( hD > 180 ) hD = 360 - hD; sD = s1 - s2; vD = v1 - v2; d += hD * hD * hW; d += sD * sD * sW; d += vD * vD * vW; } } return d; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7653 | Sam Stafford |
A couple of image compositing utilities outlined on the flight home (inspired by some difficulties I had with multiple exposure photography whilst on vacation). |