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

Using as thumbnailer #17

Open
albfan opened this issue Nov 4, 2024 · 3 comments
Open

Using as thumbnailer #17

albfan opened this issue Nov 4, 2024 · 3 comments

Comments

@albfan
Copy link
Contributor

albfan commented Nov 4, 2024

This can be easily done with:

/usr/share/thumbnailers/raw.thumbnailers

[Thumbnailer Entry]
TryExec=raviewer-thumbnailer
Exec=raviewer-thumbnailer %s %i %o
MimeType=image/x-adobe-dng;image/x-canon-cr2;image/x-canon-cr3;image/x-canon-crw;image/x-nikon-nef;image/x-nikon-nrw;image/x-olympus-orf;image/x-pentax-pef;image/x-sony-arw;image/x-sony-sr2;image/x-epson-erf;image/x-minolta-mrw;image/x-fuji-raf;image/x-panasonic-rw;image/x-panasonic-rw2;

/usr/bin/raviewer-thumbnailer

#!/bin/bash

SIZE="$1"
INPUT="$2"
OUTPUT="$3"
raviewer -f "$INPUT" -e "$OUTPUT" --endianness auto

There're only two problems:

  • Parameter size should be ignored. Using -w or --width image ends distorted.
  • On GUI there's an option "find resolutions" which offers 2 resolutions (for widths).

Using this diff we can inspect predicted widths and heights:

diff --git i/raviewer/__main__.py w/raviewer/__main__.py
index f7426a8..340c4f9 100644
--- i/raviewer/__main__.py
+++ w/raviewer/__main__.py
@@ -64,10 +64,17 @@ def run(file_path, width, height, color_format, export, args):
         img = load_image(file_path)
         if color_format == "unknown":
             color_format, _ = classify_top1(img)
+        predict_widths = [item[0] for item in predict_resolution(img, color_format)]
         if width == 0:
-            width, _ = predict_resolution(img, color_format)[0]
+            width = predict_widths[0]
         predictions, endianness = classify_all(img)
-        img = parse_image(img.data_buffer, color_format, width, Endianness[endianness].value)
+        img = parse_image(img.data_buffer, color_format, predict_widths[0], Endianness[endianness].value)
+        predict_heights = []
+        predict_heights.append(img.height)
+        img = parse_image(img.data_buffer, color_format, predict_widths[1], Endianness[endianness].value)
+        predict_heights.append(img.height)
+        print(predict_widths[0], predict_heights[0])
+        print(predict_widths[1], predict_heights[1])
         if height < 1: height = img.height
         save_image_as_file(get_displayable(img, height), export)

From this file:

pic104.zip

output is:

[480, 240]
[160, 320]

first guess looks incorrect:

pic104

Second one looks better:

pic104

  • Is there any chance to know from original file what resolution is the correct one?
  • Is possible to set a width or height honoring height/witdh proportions?
@albfan
Copy link
Contributor Author

albfan commented Nov 9, 2024

My only idea around this is detect if it creates a duplicate image (not sure how feasible that is) but guess the width and height for a raw file seems to be a common problem.

From source images on http://www.rinkydinkelectronics.com/library.php?id=53. Using raviewer as thumbnailer

UTFT_tinyFAT/Image-files

Some images choosing first guess incorrectly:

image

while other files just detect dimensions correctly:

image

@tgorochowik
Copy link
Member

It looks as though the problem you see is only visible for portrait images (i.e. correct height is larger than the correct width) and all horizontal images are detected properly. Is that assumption correct?

I don't think we have to detect whether the double images are the same (especially that they aren't, we just see odd lines on the left and even lines on the right). I think in case if the second predicted width is exactly two times smaller than the first one, we could make an assumption that the smaller one is always correct.

Alternatively (and this could be even better), we could try to give priority to dimensions with common aspect ratios. In the case of your input data 4:3 (or 3:4 for portrait mode - 240:320), would be much more common than the predicted 3:1 ratio (480x160).

Feel free to give it a go and experiment with some additional detection features

@albfan
Copy link
Contributor Author

albfan commented Nov 12, 2024

aspect ratio makes lot of sense, making a wrong guess on a unusual raw image format probably is not problematic

Will create some PR around that idea, and if is too specific we can wrap in a configurable parameter

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

No branches or pull requests

2 participants