Exemplo n.º 1
0
/**
 * Compute a linear blend of the pixel colors in two provided images according
 * to a parameter t.
 */
STImage *BlendImages(STImage *image1, STImage *image2, float t)
{
    int width = image1->GetWidth();
    int height = image1->GetHeight();
    STImage *result = new STImage(width, height, STColor4ub(255,255,255,255));
    
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            STColor4f pixel1 = STColor4f(image1->GetPixel(x, y));
            STColor4f pixel2 = STColor4f(image2->GetPixel(x, y));
            STColor4f newPixel = pixel1*(1-t) + pixel2*t;
            result->SetPixel(x, y, STColor4ub(newPixel));
        }
    }
    
    return result;
}
Exemplo n.º 2
0
STImage *FieldMorph(STImage *image,
                    const std::vector<Feature> &sourceFeatures,
                    const std::vector<Feature> &targetFeatures,
                    float t, float a, float b, float p)
{
    int width = image->GetWidth();
    int height = image->GetHeight();
    STImage *result = new STImage(width, height, STColor4ub(255,255,255,255));
    
    std::vector<Feature> interpolatedFeatures = interpolateFeatures(sourceFeatures, targetFeatures, t);
    
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            STVector2 dispSum = STVector2(0, 0);
            float weightsum = 0;
            STPoint2 X = STPoint2(x, y);
            
            int numFeatures = sourceFeatures.size();
            for (int i = 0; i < numFeatures; i++) {
                STPoint2 Pp = sourceFeatures[i].P;
                STPoint2 Qp = sourceFeatures[i].Q;
                STPoint2 P = interpolatedFeatures[i].P;
                STPoint2 Q = interpolatedFeatures[i].Q;
                
                float u = calculateU(X, P, Q);
                float v = calculateV(X, P, Q);
                STPoint2 Xp = calculateXp(Pp, Qp, u, v);
                
                STVector2 displacement = STVector2(Xp) - STVector2(X);
                float dist = calculateDistance(X, P, Q, u, v);
                float weight = calculateWeight(Q, P, a, b, p, dist);
                dispSum += displacement * weight;
                weightsum += weight;
            }
            STPoint2 Xprime = X + dispSum/weightsum;
            
            result->SetPixel(x, y, interpolatedColor(Xprime, image));
        }
    }
    
    return result;
}