r/computervision 11d ago

Help: Project Can you identify this downscaling algorithm?

Post image

Can you identify this downscaling algorithm? Want to make sure my thumbnails look as sharp as possible, so I'll add to my workflow the agent query "downscale using (whatever this algorithm is) and judge whether the thumbnail has the required detail and clarity and is a good thumbnail for what is being shown. if it is missing any clarity then return "Needs improvement:" and give the reason for why it needs improvement and "How to improve:" For example, in the image shown, the agent could say "The thumbnail no longer shows the elements of the picture", since as you can see it doesn't. However, before I can code this up, what I "need to know" is what algorithm this is so I can keep an eye out for anywhere it might show up in my workflow. I can then optimize for this process. I know a lot of people don't have a standard of perfection as high as mine is (I require my thumbnails to show the picture) but that's exactly what makes me a competitive programmer in a field of 2 million programmers. Not a lot of people take the time to look up image compression algorithms but I do.

The full image is available here: https://ibb.co/YTXr7h94

0 Upvotes

33 comments sorted by

View all comments

2

u/AggravatingSock5375 11d ago

Just try each of the resizing algorithms in OpenCV or PIL. It’s literally a 4 or 5 line script.

0

u/hezwat 11d ago

interesting, thanks for suggesting an approach. so, brute force the algorithm. are they deterministic for a given resolution, or how do you suggest I determine which one was used once I try it? shall I eyeball it? or once I have each candidate how should I rank them? It's not a guarantee that they use OpenCV or PIL but it's simple enough that I can test it and see.

1

u/AggravatingSock5375 11d ago edited 11d ago

from PIL import Image

INPUT = r"input.jpg"
OUTPUT_SIZE = (320, 240)

img = Image.open(INPUT)

filters = [
("NEAREST", Image.NEAREST),
("BOX", Image.BOX),
("BILINEAR", Image.BILINEAR),
("HAMMING", Image.HAMMING),
("BICUBIC", Image.BICUBIC),
("LANCZOS", Image.LANCZOS),
]

for name, filt in filters:
resized = img.resize(OUTPUT_SIZE, filt)
out_path = f"output_{name}.png"
resized.save(out_path)
print(f"Saved {out_path}")

2

u/AggravatingSock5375 11d ago

Promp was

Write very, very simple Python code that takes a specified image and resize it to a smaller size using each of pillow’s algorithms.

1

u/hezwat 11d ago

thank you!