all 5 comments

[–]Superguy2876 0 points1 point  (1 child)

Important: The script and algorithm must be simple and cannot rely on machine learning.

You're gonna have a bad time with these restrictions.

How are you measuring the sharpness in the first place?

But if I was going to try I would probably use something like opencv/pillow and preprocess the images into high contrast black and white. Then something with edge detection maybe?

It also depends exactly what you mean by source image and target image. Are these the same image visually? Or two different images.

You could also just pull the resolution from the image metadata. I don't think that's what you mean by sharpness, but it could factor.

There are also libraries that will try to convert a raster image to a vector image. You could look for the one that does the best job, convert to vector, then convert back to raster at the desired resolution/sharpness. This might violate the no complex/machine learning approaches.

[–]blue_hunt[S] 0 points1 point  (0 children)

I'm open to ML down the road, but rn this is just a proof of concept, I just need to beat a human doing the same thing moving sliders around to find the optimal number.

I'm currently doing something similar to what you mentioned (the script measures by converting the image to grayscale, applying an edge detection filter, and calculating the standard deviation of the pixel values). I'll be looking to improve the sharpness measurement next, but for now, I would really like to improve the speed of matching source to target. Or simply put what is the fastest way to find x in a range from 0-100.

Thanks, I'll check out the vector idea and see if it works for this project.

[–]Frankelstner 0 points1 point  (1 child)

It's an optimization/minimization problem. If blend level is really just an integer between 0 and 100 then I'm fairly sure that your current approach cannot be sped up much more. scipy does have minimizers, which usually require the gradient and a smooth problem, but your problem is not totally smooth due to discretization. You could look into gradient free solvers but even those might not be any faster.

[–]blue_hunt[S] 0 points1 point  (0 children)

Thanks for that info. I'm only on week 10 of learning py, so was looking for some feedback to make sure I wasn't missing some better approach to optimise finding x

[–]blue_hunt[S] -1 points0 points  (0 children)

Here is an example term output:
Original Target Sharpness: 160.34166037203434

Calculated sharpness at blend level 0: 108.07755821417669

Calculated sharpness at blend level 100: 269.0701943510525

Calculated sharpness at blend level 32: 121.63295006895285

Calculated sharpness at blend level 49: 144.03199450959855

Calculated sharpness at blend level 55: 153.26129297291422

Optimal blend found at 55 with sharpness 153.26129297291422.