-1

The assignment asks for : "Rename the setLuminance method as blend and have it take two pictures as parameters: the foreground and the background. Sequence through the pixels of the foreground and background simultaneously (assume they are exactly the same size) modifying the luminance of the foreground picture’s pixels. Instead of using a constant TARGET luminance as in Part A, use the luminance of the corresponding pixel of the background picture as the target. Everything else can stay the same."

and that's exactly what i have done except if I do not have sClip in the getLuminance function (to grab the average of the three color channel values,), the output will stop a third of the way before loading the picture, because it says there is an arithmetic issue and cannot divide by zero.

and my output now is 90% of the answer.

My output is

and this is the given answer

I believe I have followed every guideline, so I am mighty confused

public Luminance() {
    Picture sunflower, earth;
    sunflower = new Picture();
    earth = new Picture();
    display = new PictureDisplayer(sunflower);
    display.waitForUser();
    blend(sunflower, earth);
    display.close();
    System.exit(0);
}

private int getLuminance (Pixel p) {
   int   r;  // red value of pixel
   int   g;  // green value of pixel
   int   b;  // blue value of pixel
   int   v;  // average
   r = p.getRed();
   g = p.getGreen();
   b = p.getBlue();
   v = sClip((r + g + b)/3);
   return v;
}


private void blend(Picture sunflower, Picture earth) {
    Pixel s,e;
    int   r;  // red value of pixel
    int   g;  // green value of pixel
    int   b;  // blue value of pixel

    while ( sunflower.hasNext() ) {
        s = sunflower.next();
        e = earth.next();
        r = s.getRed(); 
        g = s.getGreen(); 
        b = s.getBlue();
        s.setRed(clip ((int) (r * (getLuminance(e))/getLuminance(s))));
        s.setGreen(clip ((int) (g * (getLuminance(e))/getLuminance(s))));
        s.setBlue(clip ((int) (b * (getLuminance(e))/getLuminance(s))));    
        }
}

private int clip(int val){
    if (val <=255){
        return val;
    }
    else {
        return 255;
    }
}
private int sClip (int val){
    if (val == 0){
        return 1;
    }
    else {
        return val;
    }
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {Luminance r = new Luminance();
    // TODO code application logic here
Itteh Kitteh
  • 437
  • 5
  • 6
alnmod
  • 13
  • 5

1 Answers1

0

I think you should change:

s.setRed(clip ((int) (r *(getLuminance(e))/getLuminance(s))));

For example:

if(getLuminance(s)!=0){
    s.setRed(clip ((int) (r * (getLuminance(e))/getLuminance(s))));
}
else{
    s.setRed(255);
}
Richard
  • 8,961
  • 3
  • 38
  • 47
kouji
  • 1