Skip to content

Commit d85933d

Browse files
committed
average + lighting
1 parent 2fe3345 commit d85933d

1 file changed

Lines changed: 56 additions & 10 deletions

File tree

src/main/java/com/aceshooting/imageprocessing/ImageAveragerNEF.java

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
public class ImageAveragerNEF extends JPanel implements ActionListener, PropertyChangeListener {
3131

32+
private static final String _AVGLIGHTEN = "Average_Lighten";
3233
private static final String _AVG = "Average";
3334
private static final String _LIGHTEN = "Lighten";
3435
private static final String _DARKEN = "Darken";
@@ -106,14 +107,16 @@ protected String doInBackground() throws Exception {
106107
if (fileName.size() != 0) {
107108
int totalFiles = fileName.size();
108109
int averagePixel[][][] = null;
110+
int lightenPixel[][][] = null;
109111
int w = 0;
110112
int h = 0;
111113
WritableRaster wRaster = null;
112114
boolean avg = false;
113115
boolean litn = false;
114-
if (selection.getSelectedItem().equals(_AVG)) {
116+
if (selection.getSelectedItem().equals(_AVG)||selection.getSelectedItem().equals(_AVGLIGHTEN)) {
115117
avg = true;
116-
} else if (selection.getSelectedItem().equals(_LIGHTEN)) {
118+
}
119+
if (selection.getSelectedItem().equals(_LIGHTEN)||selection.getSelectedItem().equals(_AVGLIGHTEN)) {
117120
litn = true;
118121
}
119122

@@ -125,10 +128,15 @@ protected String doInBackground() throws Exception {
125128
BufferedImage tempRast = reader.read(0);
126129

127130

128-
if (averagePixel == null) {
131+
if (i==0) {
129132
w = tempRast.getWidth();
130133
h = tempRast.getHeight();
131-
averagePixel = new int[w][h][3];
134+
if(avg) {
135+
averagePixel = new int[w][h][3];
136+
}
137+
if(litn) {
138+
lightenPixel = new int[w][h][3];
139+
}
132140
wRaster = Raster.createBandedRaster(DataBuffer.TYPE_INT, w, h, 3, new Point(0, 0));
133141
} else {
134142
if (tempRast.getWidth() != w || tempRast.getHeight() != h) {
@@ -137,7 +145,45 @@ protected String doInBackground() throws Exception {
137145
return _ABORTED;
138146
}
139147
}
140-
if (avg) {
148+
if(avg && litn){
149+
for (int width = 0; width < w; width++) {
150+
if (isCancelled() || progressMonitor.isCanceled()) {
151+
this.done();
152+
return _ABORTED;
153+
}
154+
for (int height = 0; height < h; height++) {
155+
156+
int RGB = tempRast.getRGB(width, height);
157+
Color c = new Color(RGB);
158+
averagePixel[width][height][0] += c.getRed();
159+
averagePixel[width][height][1] += c.getGreen();
160+
averagePixel[width][height][2] += c.getBlue();
161+
162+
lightenPixel[width][height][0] = Math.max(c.getRed(), lightenPixel[width][height][0]);
163+
lightenPixel[width][height][1] = Math.max(c.getGreen(), lightenPixel[width][height][1]);
164+
lightenPixel[width][height][2] = Math.max(c.getBlue(), lightenPixel[width][height][2]);
165+
166+
if (i == totalFiles - 1) // update the raster while
167+
// processing last file
168+
{
169+
averagePixel[width][height][0] /= totalFiles;
170+
averagePixel[width][height][1] /= totalFiles;
171+
averagePixel[width][height][2] /= totalFiles;
172+
173+
int diff=lightenPixel[width][height][0]+lightenPixel[width][height][1]+lightenPixel[width][height][2]-averagePixel[width][height][0]-averagePixel[width][height][1]-averagePixel[width][height][2];
174+
diff=diff/3;
175+
if(diff<120){
176+
wRaster.setPixel(width, height, averagePixel[width][height]);
177+
}
178+
else{
179+
wRaster.setPixel(width, height, lightenPixel[width][height]);
180+
}
181+
182+
}
183+
}
184+
}
185+
}
186+
else if (avg) {
141187
for (int width = 0; width < w; width++) {
142188
if (isCancelled() || progressMonitor.isCanceled()) {
143189
this.done();
@@ -170,14 +216,14 @@ protected String doInBackground() throws Exception {
170216
for (int height = 0; height < h; height++) {
171217
int RGB = tempRast.getRGB(width, height);
172218
Color c = new Color(RGB);
173-
averagePixel[width][height][0] = Math.max(c.getRed(), averagePixel[width][height][0]);
174-
averagePixel[width][height][1] = Math.max(c.getGreen(), averagePixel[width][height][1]);
175-
averagePixel[width][height][2] = Math.max(c.getBlue(), averagePixel[width][height][2]);
219+
lightenPixel[width][height][0] = Math.max(c.getRed(), lightenPixel[width][height][0]);
220+
lightenPixel[width][height][1] = Math.max(c.getGreen(), lightenPixel[width][height][1]);
221+
lightenPixel[width][height][2] = Math.max(c.getBlue(), lightenPixel[width][height][2]);
176222

177223
if (i == totalFiles - 1) // update the raster while
178224
// processing last file
179225
{
180-
wRaster.setPixel(width, height, averagePixel[width][height]);
226+
wRaster.setPixel(width, height, lightenPixel[width][height]);
181227
}
182228
}
183229
}
@@ -294,7 +340,7 @@ public void windowClosing(WindowEvent e) {
294340

295341
frame.setSize(this.getPreferredSize());
296342
frame.setVisible(true);
297-
selection = new JComboBox<String>(new String[]{_AVG, _LIGHTEN, _DARKEN});
343+
selection = new JComboBox<String>(new String[]{_AVGLIGHTEN,_AVG, _LIGHTEN, _DARKEN});
298344
compsToExperiment.add(selection);
299345

300346
go = new JButton("Select Folder");

0 commit comments

Comments
 (0)