Closed GerHobbelt closed 1 year ago
Thanks!
Does this really fix the windows issue with the test code that I provided for 4 component bmp image read/write? The puzzle for me is that it works on linux but gets the color components borked on windows.
Note that leptonica uses 4 space indent without tabs.
Does this really fix the windows issue with the test code that I provided for 4 component bmp image read/write? The puzzle for me is that it works on linux but gets the color components borked on windows.
Nope. (I take it you mean #675?)
Re #675: AFAICT, OP's problem is weird 🤔 : analysis (on my Win10 dev box) leads me to believe the problem is outside leptonica; I tried several ways (which uncovered this issue as a side effect) but was utterly unable to reproduce OP's issue. The most curious thing there is that the bpp changed from 32 to 24 according to his source+target bmp files, which I can't see happen anywhere in those leptonica APIs. So (IMO) the puzzle is not about MSwin, but about the precise build & run environment of #675 OP.
Apologies if my analysis report comment there is fuzzy/unclear.
I dug through his image files and tried a few things, including trying to answer the question: "as it doesn't reproduce as-is, would it reproduce if one or two leptonica calls in between were left out in the issue report?"
Result: I wasn't able to reproduce his target.bmp
no matter what I did. I got close, via adding a Convert32To24
call, but then the BGR channels are still perfectly correct and his had swapped B<->R, which is just weird as it's not explicable by an additional missing Endian swap. And this was already assuming gaps in the report, second-guessing missing intel from the original report. The other thing that's still open is: is he using a prebuilt lib from somebody else? Anyway, it's a WTH any which way I look at it.
Re #686: that one popped up while I wrote test code for #675. #686 is still pending; I haven't spent time looking into it further as it's lower prio for me now -- I still need to analyze & write demo/test code to file a few thresholding related oddities that I observed while testing tesseract and I consider those issues more pressing.
You have done a huge amount of sleuthing, and I'm amazed that you were able to do it with so little contact with leptonica!!
The PR #684 for converting 24 to 32 is really a belt-&-suspenders thing, because with one tiny exception, there should be no 24-bit pix in leptonica. All RGB pix are 32 bpp. See the comments in pixConvert24To32() for the extremely limited use of 24-bit pix. You closed 684, but I'll put that check in anyway.
As for #675, are you saying that you are not getting any error in Windows, and that sinall is the only one seeing this? If so, we can end that part of the investigation, because the code works on linux and in any event, problems with components getting shifted around should not occur on just windows. Low-level pixel stuff should be platform independent.
And as for the postulated problem with pixConvert24To32(), I will check that out. It is not covered in any of the 146 regression tests, and is barely used in the library, so it could be buggy.
Thanks for the compliment. :-) I still only somewhat grok the periphery; the important stuff, where the math becomes important, is a real struggle still -- not your code, mind you, just me hitting my own math limitations (edu + grasp) pretty hard. :'-(
example: i don't get why the counts in the histograms are multiplied by their index (= grayscale tone 0..255) when producing the sum. this is done when looking for a threshold in there (double hump in histogram -> seek valley in between). :-( that multiply feels like a triangle of weighting which I don't see the benefit or use for yet; meanwhile I'm scanning otsu and related papers to see if somebody says something in there that makes my brain +click+ but thus far: no luck. alas, maybe today. one can hope. :-)
re 684: I was fast on the trigger as I assumed you'ld pick up 685 (the fix) from the noises you made. :-)
(and, yes, I gathered that 24bpp is an oddity -- 4 bytes per pixel makes a lot of sense hardware wise, while 3 bytes per px is just a lot of old skool byte shuffling -- but I found convertTo24 in all headers while hunting ways to make 675 happen, and then it helps when write\io interfaces are orthogonal (if that's the right word for this): accept anything, either directly or by implicit conversion, only reject the obviously wrong. Your library behaviour is like that, which makes it relatively easy to go through (few exceptions to keep in mind) and use. I just grabbed what I found, than hit a snag, 's all.
re 675: yes. I cannot reproduce, nor reason through code (leptonica & his + data images provided) why it might happen. sinall is the only one. alas.
(AFK, responding via mobi. apologies for degraded msg fmt)
On Wed, Mar 22, 2023, 02:07 Dan Bloomberg @.***> wrote:
You have done a huge amount of sleuthing, and I'm amazed that you were able to do it with so little contact with leptonica!!
The PR #684 https://github.com/DanBloomberg/leptonica/issues/684 for converting 24 to 32 is really a belt-&-suspenders thing, because with one tiny exception, there should be no 24-bit pix in leptonica. All RGB pix are 32 bpp. See the comments in pixConvert24To32() for the extremely limited use of 24-bit pix. You closed 684, but I'll put that check in anyway.
As for #675 https://github.com/DanBloomberg/leptonica/issues/675, are you saying that you are not getting any error in Windows, and that sinall is the only one seeing this? If so, we can end that part of the investigation, because the code works on linux and in any event, problems with components getting shifted around should not occur on just windows. Low-level pixel stuff should be platform independent.
And as for the postulated problem with pixConvert24To32(), I will check that out. It is not covered in any of the 146 regression tests, and is barely used in the library, so it could be buggy.
— Reply to this email directly, view it on GitHub https://github.com/DanBloomberg/leptonica/pull/685#issuecomment-1478783241, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADCIHTYHXKAI3HCE2ZNNHLW5JGFJANCNFSM6AAAAAAWCM7KTU . You are receiving this because you authored the thread.Message ID: @.***>
OK, at this time I can assume that the BMP code is working properly for 4 spp on all platforms.
Small amount of background on this. I implemented the BMP I/O shims years ago because people needed it, but I did so with minimal features. For example, I didn't even allow reading of RGBA. My mantra was: if you want to use the transparency component, use PNG. Then about 6 months ago people started complaining that it didn't handle RGBA that they were getting from screen grabs. I still didn't want to mess with it, so just checked for 4 spp and returned with an error message. Then someone sent some code (isn't github great!) that worked for reading a BMP RGBA file and successfully tossed out the A layer. At that point I gave in, and implemented both reading and writing RGBA with BMP, including keeping the transparency. (I included writing both for completeness and to check that the reading was correct. As you saw in the code snippet (and you did this as well with your testing), the files were read and written several times, and also with write/read in PNG to make sure the images were all the same.
But I only tested on linux; hence the concern with issue #675. Will leave this open in case sinall reports what he is seeing in detail (as requested).
As for Otsu thresholding, it's commonly used but not very useful because it is a global threshold. I made some modifications to make it work a little better, but it's still very poor. leptonica has adaptive thresholding for doing a decent job on grayscale images where there is a large variation in background intensity. You can see examples of this by running: adaptnorm_reg display
This PR is no longer relevant.
I want to thank Ger again for taking the issue seriously, and also for providing a very useful modification to leptonica error handling -- allowing a second string in the error message, most useful when there is a failure to read a file.
fixes #684
😞 I now see indentation is a wreck (editor set to TABS here, sorry)