OpenPHDGuiding / phd2

PHD2 Guiding
https://openphdguiding.org
BSD 3-Clause "New" or "Revised" License
255 stars 115 forks source link

Live view logarithmic auto-stretch #916

Open marcocipriani01 opened 3 years ago

marcocipriani01 commented 3 years ago

Working on my app Telescope.Touch, which connects to PHD2 to get the graph and live view, I implemented a simple auto-stretch function to quickly enhance the stars without playing around with a slider. Here's how it works:

// 8-bit bitmap image
Bitmap bitmap = Bitmap.createBitmap(width, height);
// Temporary matrix
int[][] img = new int[width][height];

int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
for (int w = 0; w < width; w++) {
    for (int h = 0; h < height; h++) {
        int val = /* read a pixel value from the PHD2 socket */;
        img[w][h] = val;
        if (val > max) max = val;
        if (min > val) min = val;
    }
}

// Determine scaling factors
double logMin = Math.log10(min), multiplier = 255.0 / (Math.log10(max) - logMin);
for (int w = 0; w < width; w++) {
    for (int h = 0; h < height; h++) {
        int stretched = (int) ((Math.log10(img[w][h]) - logMin) * multiplier);
        bitmap.setPixel(w, h, Color.rgb(stretched, stretched, stretched));
    }
}
// Show the bitmap to the user...

It's Java, but it should be pretty easy to understand. The resulting image is way better than PHD2's gamma-corrected preview, and stars are easier to identify. Could be implemented in PHD2, too?

Before stretch:

After:

d33psky commented 3 years ago

Sweet. I continue to see people with stretching problems. And not grasping that it is only a screen-stretch thing. This is probably a good idea for them.