-
Notifications
You must be signed in to change notification settings - Fork 68
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
Setting manual raw_pattern #217
Comments
Can you post your complete code and upload an example image? |
Hey @letmaik, thanks for getting back to me. Let me show you an example. This is the RAW un-debayerd TIFF (I can also provide the original file if needed). The Sensor has the following bayer pattern order GBRG: Ignoring the green tint, this is what the correct debayering using https://github.com/cheind/pytorch-debayer and the GBRG bayer pattern results in: I am using the RawPy library in a very simple way: import rawpy
with rawpy.imread("image.tif") as raw_img:
img = raw_img.postprocess()
plt.imshow(img)
plt.show() However this results in the following results: Clearly rawpy is using a different bayer pattern for the debayering process. This can be seen by accessing the |
Here is the RAW TIFF: |
It's unusual to have RAW images in TIFF format. The issue is that there's not enough metadata in the file I think. The underlying library libraw then doesn't know which Bayer pattern to apply. If I may ask, where do you get this image from? Is it produced by a camera directly? |
Yes, I know, the TIFFs are in fact written by myself, so I could even add the necessary metadata if I knew what it was. I don't want to go into details, but the summary is, for performance reasons, TIFF is the fastest format we can write the data to disk. We tried several Debayering and post-processing algorithms, including the standard OpenCV, 5x5 convolutions, but libraw yielded the best results so far (on a different camera model that has the default RGGB pattern). So let me get this straight, the underlying libraw library is expecting some kind of metadata that indicates the bayer pattern, however, there is no API to set it manually. Since you are probably more familiar with the Libraw library, would you happen to know which metadata would have to be added? Perhaps if you point me in the right direction, I can try to add this feature to rawpy to set the pattern manually. |
libraw seems to have ways to read from image data without metadata as well, e.g. https://www.libraw.org/docs/API-CXX.html#open_bayer. Maybe that would suit your use case. This is not currently implemented in rawpy but it seems like a useful thing to have. There is normally quite a bit of metadata in RAW camera files that influence the postprocessing, but maybe that's not needed in your case and the Bayer pattern is enough. |
I will look into it once I have time, but I am not that familiar with making cpython bindings with a C library so not sure if I will be able to do this myself. 😅 |
I gave it a try and got it to work. I'll give you something to test soon. |
This is not officially released yet as I'd like you to try it out first. You can manually download Python wheels with this feature from the workflow artifacts (bottom right) from here: https://github.com/letmaik/rawpy/actions/runs/7734024290 This is how you would use it with import rawpy
import imageio
arr = imageio.imread("rawbayer.tiff")
with rawpy.RawPy() as raw:
raw.open_bayer(arr.tobytes(), arr.shape[1], arr.shape[0], "GBRG")
rgb = raw.postprocess() And here with import rawpy
from PIL import Image
img = Image.open("rawbayer.tiff")
with rawpy.RawPy() as raw:
raw.open_bayer(img.tobytes(), img.width, img.height, "GBRG")
rgb = raw.postprocess() For now, I'm not exposing it under a high-level interface like Please try it out and let me know if it's working as expected. |
So... just throw in some basic metadata on top (CFA pattern, color matrix, etc.) and you have yourself a DNG. 😉 See e.g. https://www.libraw.org/comment/5771#comment-5771 and https://github.com/schoolpost/PiDNG |
I am loading a Raw image (stored as tiff) however the default Raw pattern RGGB:
is not the correct one. I would need GBRG corresponding to something like:
However I haven't found a way how to set this manually in rawpy.
The text was updated successfully, but these errors were encountered: