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

How to use #2

Closed
terrainer opened this issue Feb 14, 2024 · 9 comments
Closed

How to use #2

terrainer opened this issue Feb 14, 2024 · 9 comments

Comments

@terrainer
Copy link

Hi,

I have a collection of ~58k HR images for use in training SISR.
I would like to use your code to synthesize their LR pairs.
I'm finding it rather confusing and I'm not really sure how to go about this.
I would greatly appreciate some dumbed-down instructions, if possible.

Kind regards,
terrainer

@nhauber99
Copy link
Owner

Hi,
thanks for your interest in the library! I wasn't sure if people would use it, so admittedly I didn't spend too much time on making it user friendly yet. I'll add some more example scripts and instructions for getting started in the coming days.
Best regards,
Niklas

@terrainer
Copy link
Author

Thanks Niklas! Look forward to seeing it.

@nhauber99
Copy link
Owner

I've added a Demo.py script along with a default workflow for degrading typical images. If you want to also downscale the images for your SR network, then downscale those before running the degradation.

However, you'll need to build the wrapper for the Intel IPP libraries if you want to use the demosaicing as well. This should be fairly straightforward under Windows with the provided Visual Studio project files (you'll only need to install the Intel IPP libraries and adapt the additional library and include directories of the Visual Studio project to point to the targeted python version and compile as a Release x64 library).
For linux it should work in a similar way and I've provided a build.sh script which contains a working command to compile and dynamically link the library (you may need to change some paths). However, you'll need to add the IPP lib folder to the LD_LIBRARY_PATH environment variable. (I really don't know my way around linux, so there's likely a better way to do this)

@terrainer
Copy link
Author

Thank you, I'm excited to try this. The Intel IPP libraries setup is the part I'm most confused about.
I installed the stand-alone IPP libraries and have Visual Studio installed, but I'm lost at what you mean by "adapt the additional library and include directories of the Visual Studio project..."

I'm using a conda environment on Windows.

@terrainer
Copy link
Author

Figured it out with the help of Gemini. Generated results look promising!

@nhauber99
Copy link
Owner

Open the PyIPP.sln file in Visual Studio:
image
Then right click the PyIPP project and select properties, it should look like this:
image
Here the Include Directories and Library Directories point to "C:\Users\nh\AppData\Local\Programs\Python\Python310..." which is the Python 3.10 installation path on my computer. You will need to change this to point to your python installation with the version number you want to use.
Then right click the PyIPP project and select build. Ideally this will succeed, otherwise you're maybe missing some dependencies. This article describes the workflow I've used to make the wrapper, which lists the prerequisites: https://learn.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2022
If the build succeeds you should get a PyIPP.pyd in degradr/PyIPP/PyIPP/x64/Release/. Either add this folder to your pythonpath or copy the .pyd file somewhere inside your python path. I'm using pycharm so the degradr folder is automatically added to the pythonpath when running the Demo file and this is also where I put the PyIPP.pyd file.

Ideally pull the repo again, as I've increased the amount of degradation applied by the random_degrade routine (I ran a quick test of training an SR network and it interpreted some noise as detail for some of my noisier real example images).

@nhauber99
Copy link
Owner

Oh nice! I guess I'll just leave this here in case someone else runs into the same problem as you.

@Phhofm
Copy link

Phhofm commented Feb 27, 2024

Thank you for this Project.
I was also able to degrade photos with degradr and create a 4x paired dataset (by first downscaling and then re-downscaling them with multiple different downsampling algos by half, for the model to be able to handle rescalings) very easily on ubuntu (using the Demo script, increased ZernikeKernels to 5000) , but I had removed the demosaic step for this since setting up that demosaic on ubuntu looked a bit more complex when looking at this issue.
Just something I was wondering about is if maybe a simple python package could have been used for this step like https://pypi.org/project/colour-demosaicing/ (A Python package implementing various CFA (Colour Filter Array) demosaicing algorithms) then this could also have been installed with a simple pip install command before running Demo.sh where no additional dependency installation/building/setup would be needed

@nhauber99
Copy link
Owner

Hi @Phhofm, yes that's certainly a possibility and could be used as a replacement. The main reason why I used the IPP library is that it supports the AHD demosaicing algorithm which is commonly used (as well as the VNG algorithm). It also has a (likely very optimized) native C++ implementation of the supported algorithms, which likely beats implementations relying on numpy in terms of performance.
Right now I don't have any plans for implementing this as an alternative though, It would certainly help to make the library easier to use and would be a nice addition, but I'm simply having trouble finding time for anything lately. Thank you for the suggestion though, I'll keep it in mind.

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

3 participants