我已经在每个阵列中获得了“色相饱和度”和“亮度”值。 调整每个像素的亮度(使用曝光补偿方法)后,我想使用以下方法将其重新绘制为RGB:
public class MainFrame extends JFrame {
int rgb;
Training ns = new Training();
JLabel TempL = new JLabel("Temperature");
JLabel ExpoL = new JLabel("Exposure");
JLabel SatuL = new JLabel("Saturation");
JSlider Temp = new JSlider(-50, 50, 0);
JSlider Expo = new JSlider(-50, 50, 0);
JSlider Satu = new JSlider(-50, 50, 0);
JPanel sg = new JPanel();
HSB hsb = new HSB();
int a, b;
public MainFrame () {
setSize(1200, 700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
sg.setPreferredSize(new Dimension (250, 600));
sg.setLayout(new BoxLayout(sg, BoxLayout.Y_AXIS));
sg.add(Box.createRigidArea(new Dimension(0, 75)));
sg.add(TempL);
sg.add(Box.createRigidArea(new Dimension(0, 15)));
sg.add(Temp);
sg.add(Box.createRigidArea(new Dimension(0, 75)));
sg.add(ExpoL);
sg.add(Box.createRigidArea(new Dimension(0, 15)));
sg.add(Expo);
Expo.addChangeListener(new ChangeListener () {
public void stateChanged(ChangeEvent evt) {
JSlider Expo = (JSlider) evt.getSource();
if (Expo.getValueIsAdjusting()) {
ns.value2 = (float) Expo.getValue()/100;
for(a = 0; a < ns.image.getWidth(); a++ ) {
for(b = 0; b < ns.image.getHeight(); b++ ) {
hsb.shue[a][b] = hsb.hue[a][b];
hsb.ssaturation[a][b] = hsb.saturation[a][b];
hsb.sbrightness[a][b] = hsb.brightness[a][b];
}
}
for(ns.forT1 = 0; ns.forT1 < ns.image.getWidth(); ns.forT1++ ) {
for(ns.forT2 = 0; ns.forT2 < ns.image.getHeight(); ns.forT2++ ) {
hsb.sbrightness[ns.forT1][ns.forT2] = (float) (hsb.sbrightness[ns.forT1][ns.forT2] * (Math.pow(ns.value2, 2)));
if (hsb.sbrightness[ns.forT1][ns.forT2] > 1) {
hsb.sbrightness[ns.forT1][ns.forT2] = 1;
}
if (hsb.sbrightness[ns.forT1][ns.forT2] < 0) {
hsb.sbrightness[ns.forT1][ns.forT2] = 0;
}
rgb = Color.HSBtoRGB(hsb.shue[ns.forT1][ns.forT2], hsb.ssaturation[ns.forT1][ns.forT2], hsb.sbrightness[ns.forT1][ns.forT2]);
ns.image.setRGB(ns.forT1, ns.forT2, rgb);
}
}
}
validate();
repaint();
}
});
add(ns);
add(sg, BorderLayout.EAST);
}
}
不幸的是,在我移动滑块后,图像刚刚变黑。 我的计算有什么缺陷吗?