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

Is there a way to modify the raw data #54

Closed
Melody-doudou opened this issue Aug 1, 2018 · 11 comments
Closed

Is there a way to modify the raw data #54

Melody-doudou opened this issue Aug 1, 2018 · 11 comments
Labels

Comments

@Melody-doudou
Copy link

I want to change the content of the raw data that is read from the raw file.
The error I got was an AttributeError: attribute 'raw_image_visible' of 'rawpy._rawpy.RawPy' objects is not writable.

Could you please tell me is there a way to modify the raw data?

@letmaik
Copy link
Owner

letmaik commented Aug 1, 2018

If you want to save it back as a raw file, then no. If you just want to change the raw pixels for the postprocessing, then yes, just change pixels in the arrays, e.g. raw.raw_image_visible[:] = new_data

@letmaik letmaik closed this as completed Aug 1, 2018
@Melody-doudou
Copy link
Author

Thanks Maik! I am not saving the raw file; the only process that I need is the postprocessing. I am trying to modify the raw.raw_image_visible to see what corresponding postprocessing results it would lead to.

I have a couple of more questions here. Does the postprocessing process only depend on the raw_image_visible matrix, or is it that it depends on other options in the raw file as well? I tried to fill a new_data (which is 100x100) into raw.raw_image_visible (which is 200x200). It led to a ValueError though: could not broadcast input array from shape (100,100) into shape (200,200). I modified the new_data as the upper left block contains the actual matrix values, while other parts are all set to zeros; then fed it into raw.raw_image_visible and it worked.

However, the results aren't what I was originally expecting for. My goal is trying to figure out what operations I could do on the raw data so that it leads to a simulated corresponding low-resolution counterpart of the original image. What I did earlier - by selecting a subset of the raw data doesn't lead to an image that is slightly blurry, but some points that have a color difference (I also tried bicubic interpolation of the raw data, seems it doesn't work either). Do you have any clue about it, if the above-mentioned makes sense to you. Thank you so much. :)

@letmaik
Copy link
Owner

letmaik commented Aug 2, 2018

I you just want to reduce the output resolution, maybe the half_size=True option is a solution. But this is probably not what you have in mind when talking about "simulating".

Before I continue, do you understand the concept of Bayer matrices?

@Melody-doudou
Copy link
Author

Thanks for your reply. Yeah that is not what I had in mind by setting "half_size=True".

I am actually trying to investigate the SR(super-resolution) problem by using raw data. As the raw data technically contains more information (hasn't been through all the processings) and offers higher controllability, my thought is that maybe it is more suitable for the SR problem of being able to restore more details. The traditional SR problem achieves the low-resolution images using bicubic interpolation.

img_2 = imresize(imresize(img, 1/2, 'bicubic'), [size(img, 1), size(img, 2)], 'bicubic');

For raw data though, I don't really have a clue of how to achieve similar "simulated" low-resolution images.

My basic understanding of Bayer matrices is that in raw data, each pixel value retains the intensity pixel value of only one color channel of the three RGB channels. The whole raw data is organized in Bayer pattern (RGBG) as blocks. I am all new into this so the understanding can be not very accurate.

@Melody-doudou
Copy link
Author

I actually want to enable the "half_size=True" option, but in the opposite direction. I am not sure this option is achieved from a down-sampling the RGB image of original image size, or from the raw data.

Given both raw data and RGB data of the original image size, instead of achieving a half-sized RGB image, I am wondering what the corresponding raw data would be like that could generate the half-sized RGB image.

@letmaik
Copy link
Owner

letmaik commented Aug 3, 2018

Given that rawpy is just a simple wrapper around libraw, I have the feeling that your question should better be asked in a general raw photography discussion forum than here. You will get more helpful answers.

@Melody-doudou
Copy link
Author

Okay, I see. Thanks a lot for your help! :)

@Melody-doudou
Copy link
Author

Could you still tell me your answer to this question, does the postprocessing process only depend on the raw_image_visible matrix, or is it that it depends on other options in the raw file as well?

@letmaik
Copy link
Owner

letmaik commented Aug 3, 2018

Postprocessing mostly depends on the image matrix, the chosen postprocessing parameters, and, if the parameters don't override it, then things like camera whitebalance can be used directly from the file metadata.

@Ir1d
Copy link

Ir1d commented Sep 19, 2019

@Melody-doudou Hi, have you solved this? Can you share your solution on how to perform postprocessing on downsampled images?
Since the numpy array is downsampled, it cant overwrite the original array

@letmaik
Copy link
Owner

letmaik commented Sep 19, 2019

@Ir1d If you downsample then you destroy the Bayer matrix, which means you can't postprocess anymore. Please ask such questions on stackoverflow.

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

No branches or pull requests

3 participants