【发布时间】:2015-11-09 05:33:51
【问题描述】:
作业要求:“将 setLuminance 方法重命名为 blend 并让它拍摄两张图片作为参数:前景和背景。同时对前景和背景的像素进行排序(假设它们的大小完全相同)修改前景图片像素的亮度。不要像 A 部分那样使用恒定的 TARGET 亮度,而是使用背景图片的相应像素的亮度作为目标。其他一切都可以保持不变。
这正是我所做的,除非我在 getLuminance 函数中没有 sClip(获取三个颜色通道值的平均值),输出将在加载图片之前停止三分之一,因为它说有一个算术问题,不能被零除。
我现在的输出是答案的 90%。
我相信我已经遵循了每一条准则,所以我很困惑
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
【问题讨论】:
标签: java image image-manipulation pixels brightness