Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement interpolation in LUT calculation #92

Closed
bramstroker opened this issue Aug 20, 2021 · 6 comments
Closed

Implement interpolation in LUT calculation #92

bramstroker opened this issue Aug 20, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@bramstroker
Copy link
Owner

No description provided.

@bramstroker bramstroker added the enhancement New feature or request label Aug 20, 2021
@nepozs
Copy link
Contributor

nepozs commented Aug 20, 2021

Maybe I misunderstood idea, but I've seen discussion in #87 and I'm not sure if that is proper way of development path - I mean optimization of computing power (just things should be as simple as possible) - so it is in current solution of powercalc component.

I think it is no need to use complicated calculations in powercalc component, if any interpolation really should be done it should be done at stage creating LUT file and in my opinion LUT files really could be optimized (just example with "brighness 1" tells a lot), but I can't imagine simple solution for use variable step in measure script (so it could replace interpolation).

@bramstroker
Copy link
Owner Author

I have an idea how to do it, this won't be any heavy calculations. But I'll lookup just the lower closest brightness value en highest closest brightness value. And than interpolate depending on the selected brightness level. I won't do anything in the other dimensions (hue, saturation, mired).
The lookup is just a memory pointer as the whole LUT file is loaded into memory once, so this is not CPU or resource heavy in comparence to the current implementation.
I am not sure I will implement this at all but created the issue just for reference. When I have to add lot of complexity I will not implement, because it will also be a maintenance issue.
This is no replacement to accept LUT files with less measure points (they will still need many 23.000 for hs mode), but just an even better calculation of power for the current LUT files.

@smonesi
Copy link
Contributor

smonesi commented Aug 20, 2021

As I mentioned in my other PR, I wrote this simple python script that reads an hs file and outputs a similar file with any desired step of brightness/hue/saturation using the interpolation provided by scipy.interpolate (which is computationally intensive, I would definitely not use this in real-time code):

import csv
import numpy as np
from scipy.interpolate import griddata
from typing import Iterator

FILENAME='export/LLC001/hs.csv'

def inclusive_range(start: int, end: int, step: int) -> Iterator[int]:
    i = start
    while i < end:
        yield i
        i += step
    yield end

def main():
    grid_bri,grid_hue,grid_sat = np.mgrid[1:256:1,1:65536:1000,1:255:1]
    points = []
    values = []

    with open(FILENAME) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        next(reader, None)
        print("bri,hue,sat,watt")
        for row in reader:
            #print("%d,%d,%d,%.12g"%(int(row[0]),int(row[1]),int(row[2]),round(float(row[3]),2)))
            point = [row[0],int(row[1]),row[2]]
            points.append(point)
            values.append(row[3])

        fullgrid = griddata(points, values, (grid_bri,grid_hue,grid_sat), method='linear')

        for bri in inclusive_range(1, 255, 20):
            for sat in inclusive_range(1, 254, 40):
                for hue in inclusive_range(1, 65535, 2000):
                    print("%d,%d,%d,%.12g"%(bri,hue,sat,round(fullgrid[int(bri-1),int((hue-1)/1000),int(sat-1)],2)))

if __name__ == "__main__":
  main()

I'm not even sure it works correctly, mathematically speaking, but I checked some outputs and the results seem good.

I think that hue values cannot be interpolated in a meaningful way if the samples are too sparse, however brightness and even saturation should.

@bramstroker
Copy link
Owner Author

I'm not that familiar with numpy and scipy yet, but this looks fine to interpolate values for the CSV this way using the magic of scipy.interpolate. If you checked some samples and they are very close to the measured values I am happy to merge the LUT files without having you to redo all of them.

@bramstroker
Copy link
Owner Author

Proof of concept #170. Will need to do some further testing.

@bramstroker
Copy link
Owner Author

This has been merged in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants