Reading CR2 (Canon RAW) images into MATLAB
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I was wondering if anyone could help me to read in some CR2 images into MATLAB?
I have tried just using imread but it just reads the image as an 8 bit. I can used Adobe's DNG converter as people have suggested but would rather have the whole code automated. Other questions like this are a few years old so was hoping some people had new suggestions.
Thanks!
0 commentaires
Réponses (2)
Arvind Narayanan
le 28 Mar 2017
It is possible to read CR2 data into MATLAB with the normal workflow for reading images. You can try the following sample code snippet:
A=imread('sample.CR2');
imshow(A);
imwrite(A,'filename.jpg');
2 commentaires
Steffen B. Petersen
le 4 Mai 2019
The code below is essentially what Arvind proposes :
the red channel of the image displayed (an astronomical image with a few high intensity stars) is a correct representation of what MATLABN displayes - but clearly there is a problem with the lowest intensity levels of the image. It appears as if MATLAB is utilizing lossy compression schemes, which in apprearance looks like JPEG compression.
I would like to know how to swicth off the compression, if anybody knows.![matlab_cr2.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218015/matlab_cr2.jpeg)
![matlab_cr2.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218015/matlab_cr2.jpeg)
[myfile,mypath]=uigetfile({'*.cr2'});
>> mygray2=myim(:,:,1);
>> mytiny2=mygray2(2000:2500,3300:3800);
>> figure(3);
>> imshow(mytiny2,[10 30]);
DGM
le 23 Avr 2024
A CR2 file is structured like a TIFF. It contains multiple images, both compressed and uncompressed. Two of these images are JPG, only one of which is lossless (the CFA data). When picked up by imread(), it looks like it's just treating the image as a TIFF and reading the first IFD, which would be the lossy preview JPG.
Either use raw2rgb() to get a demosaiced RGB image from the CFA data, or use rawread() to get the CFA data to reconstruct the image yourself.
Otherwise, consider these resources.
Format information (see the resources at the end): http://lclevy.free.fr/cr2/
Processing RAW images in MATLAB: https://rcsumner.net/raw_guide/RAWguide.pdf
That guide PDF is fairly old, but the workflow it describes is essentially what you're avoiding by using raw2rgb().
Dinesh Iyer
le 22 Avr 2024
The raw2rgb and rawread functions will support RAW file formats.
0 commentaires
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!