Skip to content

Commit c7365b2

Browse files
committed
Patches from @fanckush on issue jcelaya#113
There was a rejected hunk against ImageStack where I made different changes for jcelaya#216 DO NOT MERGE/CHERRY-PICK - commit authorship is wrong and needs to be fixed!
1 parent a331ae2 commit c7365b2

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

Diff for: src/Image.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ void Image::buildImage(uint16_t * rawImage, const RawParameters & params) {
4444
size_t size = width*height;
4545
brightness = 0.0;
4646
max = 0;
47+
min = params.black * 100; // some inital big value
4748
for (size_t y = 0, ry = params.topMargin; y < height; ++y, ++ry) {
4849
for (size_t x = 0, rx = params.leftMargin; x < width; ++x, ++rx) {
4950
uint16_t v = rawImage[ry*params.rawWidth + rx];
5051
(*this)(x, y) = v;
5152
brightness += v;
5253
if (v > max) max = v;
54+
if (v < min) min = v;
5355
}
5456
}
5557
brightness /= size;
56-
response.setLinear(params.max == 0 ? 1.0 : 65535.0 / params.max);
58+
// response.setLinear(params.max == 0 ? 1.0 : 65535.0 / params.max);
59+
response.setLinear(1.0);
5760
subtractBlack(params);
5861
}
5962

@@ -165,9 +168,11 @@ void Image::computeResponseFunction(const Image & r) {
165168
int pos = y * width + x;
166169
double v = usePixels[pos];
167170
double nv = rUsePixels[pos];
168-
if (v >= nv && v < satThreshold) {
169-
numerator += v * r.response(nv);
170-
denom += v * v;
171+
if (v <= nv && nv < satThreshold) {
172+
if ((nv - (double)r.min) / ((double)r.max - (double)r.min) > 0.1) {
173+
numerator += v * r.response(nv);
174+
denom += v * v;
175+
}
171176
}
172177
}
173178
}

Diff for: src/Image.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Image : public Array2D<uint16_t> {
104104
QString filename;
105105

106106
std::unique_ptr<Array2D<uint16_t>[]> scaled;
107-
uint16_t satThreshold, max;
107+
uint16_t satThreshold, max, min;
108108
double brightness;
109109
ResponseFunction response;
110110
double halfLightPercent;

Diff for: src/ImageIO.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void ImageIO::save(const SaveOptions & options, ProgressIndicator & progress) {
183183
params.width = stack.getWidth();
184184
params.height = stack.getHeight();
185185
params.adjustWhite(stack.getImage(stack.size() - 1));
186-
Array2D<float> composedImage = stack.compose(params, options.featherRadius);
186+
Array2D<float> composedImage = stack.compose(params, options.featherRadius, options.bps);
187187

188188
progress.advance(33, "Rendering preview");
189189
QImage preview = renderPreview(composedImage, params, stack.getMaxExposure(), options.previewSize <= 1);

Diff for: src/ImageStack.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#include <algorithm>
24+
#include <cmath>
2425

2526
#include "BoxBlur.hpp"
2627
#include "ImageStack.hpp"
@@ -166,8 +167,8 @@ void ImageStack::crop() {
166167

167168
void ImageStack::computeResponseFunctions() {
168169
Timer t("Compute response functions");
169-
for (int i = images.size() - 2; i >= 0; --i) {
170-
images[i].computeResponseFunction(images[i + 1]);
170+
for (int i = 1; i < images.size(); ++i) {
171+
images[i].computeResponseFunction(images[i - 1]);
171172
}
172173
}
173174

@@ -394,7 +395,7 @@ static Array2D<uint8_t> fattenMask(const Array2D<uint8_t> & mask, int radius) {
394395
}
395396
#endif
396397

397-
Array2D<float> ImageStack::compose(const RawParameters & params, int featherRadius) const {
398+
Array2D<float> ImageStack::compose(const RawParameters & params, int featherRadius, int bit_depth) const {
398399
int imageMax = images.size() - 1;
399400
BoxBlur map(fattenMask(mask, featherRadius));
400401
measureTime("Blur", [&] () {

Diff for: src/ImageStack.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ImageStack {
4848
void crop();
4949
void computeResponseFunctions();
5050
void generateMask();
51-
Array2D<float> compose(const RawParameters & md, int featherRadius) const;
51+
Array2D<float> compose(const RawParameters & md, int featherRadius, int bit_depth) const;
5252

5353
size_t size() const { return images.size(); }
5454

0 commit comments

Comments
 (0)