Bug 502200 - Set automatically the rotation flag for pictures in portrait format with a dedicated scanning tool.
Summary: Set automatically the rotation flag for pictures in portrait format with a de...
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Metadata-Engine (show other bugs)
Version: 8.6.0
Platform: Microsoft Windows Microsoft Windows
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-30 11:22 UTC by Braun.Lot
Modified: 2025-04-05 17:08 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 8.7.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Braun.Lot 2025-03-30 11:22:24 UTC
This is a wish or a suggestion.
I do have a lot (several thousand) scanned images from slides. Due to the scan process, they are all in landscape orientation.
Just like a scan for faces or objects, I would like to have digikam tag all pictures that are in portrait format.
Comment 1 Michael Miller 2025-03-31 19:05:53 UTC
(In reply to Braun.Lot from comment #0)
> This is a wish or a suggestion.
> I do have a lot (several thousand) scanned images from slides. Due to the
> scan process, they are all in landscape orientation.
> Just like a scan for faces or objects, I would like to have digikam tag all
> pictures that are in portrait format.

Hello Braun,
Please help me understand your request.  Is the goal to find all the images so you can rotate them to the correct orientation?

Cheers,
Mike
Comment 2 Braun.Lot 2025-04-01 07:51:45 UTC
Hello Mike,
to put it in other words:
All Images are in Landscape orientation. I would like for digikam to set the correct orientation flag.
(Or at least to flag every picture which seams to have a wrong orientation flag)
Hope that is better phrased.
Cheers
Lothar
Comment 3 Michael Miller 2025-04-01 10:29:45 UTC
(In reply to Braun.Lot from comment #2)
> Hello Mike,
> to put it in other words:
> All Images are in Landscape orientation. I would like for digikam to set the
> correct orientation flag.
> (Or at least to flag every picture which seams to have a wrong orientation
> flag)
> Hope that is better phrased.
> Cheers
> Lothar

Hi Lothar,
We are introducing an AI based auto-rotate function in digiKam 8.7.0.  digiKam examines the image and automatically rotates the image to the correct orientation.  You can try it now in the digiKam 8.7.0 daily builds.

Will this help?

Cheers,
Mike
Comment 4 Braun.Lot 2025-04-01 12:30:54 UTC
Hello Mike,
sounds really good!
Could you link it to this bug so I know when to try it?
Thanks a lot
Lothar
Comment 5 caulier.gilles 2025-04-01 12:41:24 UTC
Hi,

The code is already compiled with this new feature in the pre-release build available here :

https://files.kde.org/digikam/

Best

Gilles Caulier
Comment 6 Michael Miller 2025-04-01 13:15:06 UTC
Hi Lothar,
You can try it now. It was added last week. Download the latest pre-release version of digiKam 8.7.0

https://files.kde.org/digikam/

Here's a quick demo:
https://imgur.com/a/OXcvybd

Cheers,
Mike
Comment 7 Braun.Lot 2025-04-01 15:00:37 UTC
Hi Mike,
this would be just the feature I am looking for - if it would work somewhat reliable.
Is there any chance to train it, or do you need some test data? With my tiff files it is (sadly) unusable.
cheers
Lothar

PS An additional request would be to add it to the maintenance pipeline.
Comment 8 Michael Miller 2025-04-01 15:44:37 UTC
(In reply to Braun.Lot from comment #7)
> Hi Mike,
> this would be just the feature I am looking for - if it would work somewhat
> reliable.
> Is there any chance to train it, or do you need some test data? With my tiff
> files it is (sadly) unusable.
> cheers
> Lothar
> 
> PS An additional request would be to add it to the maintenance pipeline.

Hi Lothar,
Can you please try it with a single image, and not multiple selected images? Also, do you mind sending me a copy of a file that's not working?

Cheers,
Mike
Comment 9 Braun.Lot 2025-04-01 16:19:56 UTC
Hi Mike,
the images are about 100 MB each. so just a Link: https://magentacloud.de/s/ZbCLwrii5DMPjEG
Bild025.tif is not rotated (false)
Bild033.tif is rotated (false positive)
Bild034.tif is always rotated (portrait/landscape/portrait/landscape/...)
Everything tested with single select and rotated with ctrl/shift up
Comment 10 Michael Miller 2025-04-03 02:06:12 UTC
(In reply to Braun.Lot from comment #9)
> Hi Mike,
> the images are about 100 MB each. so just a Link:
> https://magentacloud.de/s/ZbCLwrii5DMPjEG
> Bild025.tif is not rotated (false)
> Bild033.tif is rotated (false positive)
> Bild034.tif is always rotated (portrait/landscape/portrait/landscape/...)
> Everything tested with single select and rotated with ctrl/shift up

Hi Lothar,
I'm working on the autorotate problem.  It looks like the .tiff image isn't being loaded correctly.  As a test, can you please save a few of the .tiff files as jpeg and then try the autorotate feature on the jpegs?  I tried this with same sample images you sent (thank you!), and autorotate was 100% accurate (3 images is not a good sample size).

Meanwhile, I'll keep looking at why the .tiff files aren't loading correctly.

Cheers,
Mike
Comment 11 Braun.Lot 2025-04-03 14:16:12 UTC
Hi Mike,
converted to jpg they work much better. But to do a bulk test it would be nice to can at least mark 100 files in one album and not to rotate every single one.

I tried to convert them using irfanview but got no reasonable results - something off with the color.
ImageMagick worked like a treat.

I will add two more files in the next minutes, both tiff and jpg, to the linked directory. Bild009 does not get rotated and Bild026 gets upside down.
I have no problem to provide more examples if that helps.
Cheers and thank you for your patience and the good work
Lothar
Comment 12 Michael Miller 2025-04-03 16:45:16 UTC
(In reply to Braun.Lot from comment #11)
> Hi Mike,
> converted to jpg they work much better. But to do a bulk test it would be
> nice to can at least mark 100 files in one album and not to rotate every
> single one.
> 
> I tried to convert them using irfanview but got no reasonable results -
> something off with the color.
> ImageMagick worked like a treat.
> 
> I will add two more files in the next minutes, both tiff and jpg, to the
> linked directory. Bild009 does not get rotated and Bild026 gets upside down.
> I have no problem to provide more examples if that helps.
> Cheers and thank you for your patience and the good work
> Lothar

Hi Lothar,
I found the problem and I'm working on a fix now.  The problem is the tiffs are 16 bit, and the AI model wants 8 bit images.  My code to convert an image from 16 bit to 8 bit had a flaw in it which made the 8 bit image I was passing to the AI model unreadable.

The fix should be added to digiKam in a day or so.  Once it's added, you will be able to use your original source Tiffs without a problem.

> Bild009 does not get rotated and Bild026 gets upside down.
The AI isn't 100% accurate, but testing has proven it is well over 95% accurate.  Sometimes you need to run autorotate on the image again, and sometimes the AI just can't figure it out.

Cheers,
Mike
Comment 13 Michael Miller 2025-04-03 22:43:55 UTC
Git commit 0cb188620947be6e6fc87058287ffa411440d606 by Michael Miller.
Committed on 03/04/2025 at 22:40.
Pushed by michmill into branch 'master'.

fix 16 to 8 bit conversion when creating a cv::Mat
FIXED-IN: 8.7.0

M  +32   -5    core/libs/autorotator/autorotator.cpp
M  +46   -15   core/libs/qtopencvimg/qtopencvimg.cpp
M  +0    -1    core/libs/qtopencvimg/qtopencvimg.h

https://invent.kde.org/graphics/digikam/-/commit/0cb188620947be6e6fc87058287ffa411440d606
Comment 14 Michael Miller 2025-04-03 22:46:24 UTC
Hi Lothar,
The fix should be in the daily build available Saturday.  Please let me know if you have any problems or questions.

Thanks for your help!

Cheers,
Mike
Comment 15 Braun.Lot 2025-04-05 16:46:22 UTC
Hi Mike,
just checked and it is really good! Thank you.

I am not sure about it, but it seems to me, that there are a few (just two or three out of 100) images which give different results for tiff and jpg format.
I will have a closer look at that, but the next point is much more important for me:

I would really appreciate it, if I could let it run over at least a hundred, better a few thousand pictures.
Is that planned? 
Marking all thumbnails in thumbnail view is possible, but does not give correct results.
Should I file a new bug for that?

Thank you very much
Lothar
Comment 16 Michael Miller 2025-04-05 17:08:16 UTC
(In reply to Braun.Lot from comment #15)
> Hi Mike,
> just checked and it is really good! Thank you.
> 
> I am not sure about it, but it seems to me, that there are a few (just two
> or three out of 100) images which give different results for tiff and jpg
> format.
> I will have a closer look at that, but the next point is much more important
> for me:
> 
> I would really appreciate it, if I could let it run over at least a hundred,
> better a few thousand pictures.
> Is that planned? 
> Marking all thumbnails in thumbnail view is possible, but does not give
> correct results.
> Should I file a new bug for that?
> 
> Thank you very much
> Lothar

Hi lothar,
> I am not sure about it, but it seems to me, that there are a few (just two
> or three out of 100) images which give different results for tiff and jpg
> format.
That sounds about right for the accuracy of the AI model.  Unfortunately no AI is going to be 100% perfect.

> I would really appreciate it, if I could let it run over at least a hundred,
> better a few thousand pictures.
> Is that planned? 
Have you tried the Batch Queue Manager for processing a large number of files?  Make sure you read the BQM documentation first.  The default behavior is to create new copies of the modified image, and that may not be what you want.
https://docs.digikam.org/en/batch_queue.html

> Marking all thumbnails in thumbnail view is possible, but does not give
> correct results.
> Should I file a new bug for that?
Yes, please.  This will help us track the fix for multiple images selected in the thumbnail view.

Thanks for helping us out!

Cheers,
Mike