Skip to content

Commit

Permalink
Patches from @fanckush on issue jcelaya#113
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
Entropy512 committed Nov 24, 2022
1 parent a331ae2 commit c7365b2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ void Image::buildImage(uint16_t * rawImage, const RawParameters & params) {
size_t size = width*height;
brightness = 0.0;
max = 0;
min = params.black * 100; // some inital big value
for (size_t y = 0, ry = params.topMargin; y < height; ++y, ++ry) {
for (size_t x = 0, rx = params.leftMargin; x < width; ++x, ++rx) {
uint16_t v = rawImage[ry*params.rawWidth + rx];
(*this)(x, y) = v;
brightness += v;
if (v > max) max = v;
if (v < min) min = v;
}
}
brightness /= size;
response.setLinear(params.max == 0 ? 1.0 : 65535.0 / params.max);
// response.setLinear(params.max == 0 ? 1.0 : 65535.0 / params.max);
response.setLinear(1.0);
subtractBlack(params);
}

Expand Down Expand Up @@ -165,9 +168,11 @@ void Image::computeResponseFunction(const Image & r) {
int pos = y * width + x;
double v = usePixels[pos];
double nv = rUsePixels[pos];
if (v >= nv && v < satThreshold) {
numerator += v * r.response(nv);
denom += v * v;
if (v <= nv && nv < satThreshold) {
if ((nv - (double)r.min) / ((double)r.max - (double)r.min) > 0.1) {
numerator += v * r.response(nv);
denom += v * v;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Image : public Array2D<uint16_t> {
QString filename;

std::unique_ptr<Array2D<uint16_t>[]> scaled;
uint16_t satThreshold, max;
uint16_t satThreshold, max, min;
double brightness;
ResponseFunction response;
double halfLightPercent;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void ImageIO::save(const SaveOptions & options, ProgressIndicator & progress) {
params.width = stack.getWidth();
params.height = stack.getHeight();
params.adjustWhite(stack.getImage(stack.size() - 1));
Array2D<float> composedImage = stack.compose(params, options.featherRadius);
Array2D<float> composedImage = stack.compose(params, options.featherRadius, options.bps);

progress.advance(33, "Rendering preview");
QImage preview = renderPreview(composedImage, params, stack.getMaxExposure(), options.previewSize <= 1);
Expand Down
7 changes: 4 additions & 3 deletions src/ImageStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <algorithm>
#include <cmath>

#include "BoxBlur.hpp"
#include "ImageStack.hpp"
Expand Down Expand Up @@ -166,8 +167,8 @@ void ImageStack::crop() {

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

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

Array2D<float> ImageStack::compose(const RawParameters & params, int featherRadius) const {
Array2D<float> ImageStack::compose(const RawParameters & params, int featherRadius, int bit_depth) const {
int imageMax = images.size() - 1;
BoxBlur map(fattenMask(mask, featherRadius));
measureTime("Blur", [&] () {
Expand Down
2 changes: 1 addition & 1 deletion src/ImageStack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ImageStack {
void crop();
void computeResponseFunctions();
void generateMask();
Array2D<float> compose(const RawParameters & md, int featherRadius) const;
Array2D<float> compose(const RawParameters & md, int featherRadius, int bit_depth) const;

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

Expand Down

0 comments on commit c7365b2

Please sign in to comment.