5

I have a series of JPEG images taken with Canon Powershot to JPEG. How can I convert/transform them to RAW images?

Not with a graphical tool, but from the command line!

NB : Using raw images to stack them in Siril astrophoto application (https://siril.org/fr/)

18
  • 48
    Maybe you will receive answers more useful for you if you tell us why you want raw images (edit the question). Compare XY problem. Jan 24, 2021 at 12:07
  • 7
    Welcome out on SuperUser. Note that the jpg saving option is lossy. If you need to convert again into a specific RAW format, you need to know those specifications. Usually it is meaningless because the flaws are already iside the images and you cannot go back. But if you need, edit your post adding the model and maybe it will be possible to give you some hints or solutions.
    – Hastur
    Jan 24, 2021 at 23:19
  • 8
    Lolotux, you do not win a dime when doing this. Probably you heard about the advantages of the RAW format over JPEG. That is true. But you can only profit from it when your cameras saves them in RAW format (at the begining of the production chain). Having had a Canon Powershot (A75) myself I remember there was a setting where the camera would write RAW and middle quality jpeg instead of high quality jpeg. Converting afterwards is like recoding an old video in 720x576 to 4k. You won't get a single detail more out of it. Furthermore, there is more software that is processing JPEG than RAW.
    – r2d3
    Jan 24, 2021 at 23:41
  • 19
    RAW is not a format. Rather it is a label that means sensor data from a manufacturer. Different hardware generates different sensor data so there is no RAW format but rather there are multiple different sensor data formats that are called RAW because they are raw sensor data (by raw I mean unprocessed like food before being cooked and RAW also means raw only some people feel like they need to capitalize it)
    – slebetman
    Jan 25, 2021 at 3:44
  • 7
    @PeterMortensen - There are three different Canon RAW formats. They abandoned CIFF in 2004, for TIFF-based CR2 & now QT-based CR3. exiftool.org/canon_raw.html "Converting to RAW" is still not a good idea & nothing absolutely needs RAW as input, whether the conversion is otherwise pointless or not. if you were to attempt any kind of 'rough guess' conversion, then the more open DNG format would be as good as any to aim for - helpx.adobe.com/photoshop/digital-negative.html
    – Tetsujin
    Jan 25, 2021 at 10:52

5 Answers 5

58

Original RAW images cannot be restored.

Selecting JPEG instead of RAW saves space by sacrificing quality.
This operation is irreversible and lossy.
Simply speaking this means you can't go back.

Sadly you may only select RAW format instead of JPEG next time before you shot.

Note: You could technically find a way to turn the current jpg image into RAW format, but it will not be the same RAW image you might have if you shot and saved directly in RAW format.


Searching in the Canon support you may read

the camera can capture images in JPEG and RAW format.

JPEG
Images Processed in the camera for optimal image quality and compressed to reduce file size. However, the compression process is irreversible, and images cannot be restored to their original, unprocessed state. Image processing may also cause some loss of image quality.

RAW "Raw" (unprocessed) data, recorded with essentially no loss of image quality from the camera's image processing. The data cannot be used in this state for viewing on a computer or printing. You must first process images on the camera or use the software (Digital Photo Professional) to convert images to JPEG or TIFF files. Images can be adjusted with minimal loss of image quality.

10
  • 2
    Note that there is not currently a single standard "RAW format". Jan 26, 2021 at 17:38
  • 1
    @RockPaperLz-MaskitorCasket Right and proper. RAW formats are service formats used by the manufacturer to quickly save the contents of the CCD into the buffer and in case on the storage device. They depend on choices dictated by the geometry of the CCD etc etc... Seldom only the manufacturer knows the functions used to convert the RAW picture into another format. Often the transformation is not reversible. See this answer below for some words more.
    – Hastur
    Jan 26, 2021 at 18:31
  • 1
    Maybe it is poorly worded. With "Seldom ... Often..." I just wanted to express my impression: sometimes the algorithm is not disclosed, more often there are (see convert) ways of converting a specific RAW format into (e.g.) JPEG, even more often the algorithms are not invertible (simple example: shrinking 12 or 14-bits into 8)...
    – Hastur
    Jan 26, 2021 at 19:05
  • 2
    I am always curious about downvoters ... Please comment and let me (we) know what you disagree, it might be useful to know.
    – Hastur
    Jan 27, 2021 at 13:16
  • 1
    @data I see. I think your interpretation is likely due to the ambiguities of the English language. Try reading what I wrote this way: "RAW format is not a single standard". In other words, there are many RAW formats. Jan 27, 2021 at 23:25
30

"Raw" is not a well defined format. Examining Wikipedia Raw image format, I counted 43 raw formats, each depending on the camera model.

One of the best image packages around is ImageMagick, available as a package on Linux or as a download, which supports a few RAW formats. Use its commands of magick or convert.

However, the quality of the result would be very poor. JPEG is processed image data while RAW is not. Typically, RAW-files have 12-14-bit per pixel which means up to 16384 values. JPEG can have only 256 luminance values per RGB channel. This means that JPEG contains much less data than a corresponding RAW-file. So there is no good way to convert a JPEG to RAW.

9
  • 22
    Absolutely. You shouldn't even attempt this. You will not get what you think you might get. See photo.stackexchange.com/questions/73475/… for some more reasons & possibilities for conversion if you're not convinced yet. There is no way to get back the information lost by saving your originals as jpg. Just remember to switch your camera to RAW before using it again.
    – Tetsujin
    Jan 24, 2021 at 13:10
  • @Steve Hello. If you talk about (scientfic) data, you have already compromised it. I agree with you that if the filter is well done you will not introduce further changes in the single pixel values by converting them from jpg to RAW. But if not, you will do it... again. And if you just need to work on actual jpg images, you don't need any other layers of processing, you can start right from the images you have.
    – Hastur
    Jan 24, 2021 at 23:26
  • The bits-per-pixel numbers you've quoted are so misleading that it actually turns out JPEG has more bits per pixel than RAW (14 bits vs. 3x8 bits). Without explanation how RAW files work this part is very confusing.
    – gronostaj
    Jan 25, 2021 at 13:22
  • @gronostaj: I meant 12-14 bits per pixel color for RAW, compared to 8 for JPEG. There are formats which use even more bits.
    – harrymc
    Jan 25, 2021 at 13:26
  • 3
    Hi, sorry to say but Imagemagick programs and libraries only support Reading the Canon CRW and CR2 formats... (Check it with the command line in this answer) So you can convert from CRW to JPEG but not the other way. At least not in a simple way.
    – Hastur
    Jan 25, 2021 at 17:38
11

Difficulties and opportunity of trying to convert JPEG into RAW format.

It is not always possible to convert a JPEG file to the original RAW file.
Note: I speak about original or specific RAW format because it is not a standard: RAW formats are service formats, different one from another, used by the manufacturer to quickly save the contents of the CCD into the buffer and in case on the storage device.

Limits. You might be able to turn it into a valid RAW format, but that doesn't mean the individual values stored in the new RAW file are the same as you might have if you saved the shot directly in RAW format.

Opportunity. It is not said that even if you can convert a JPEG image to RAW format and start from it for processing, the final result will be better than if you start directly from the JPEG you already have. In fact you will apply a filter (algorithm) that transforms one format into another and that can introduce further alterations.

Difficulties. Nonetheless, once you know the specific RAW format you may find a way to formally convert the image into your RAW format. This will involve not trivial programming efforts, starting from the modeling of the inverse transformation and ending into coding in the preferred language the algorithm.

Existing Programs. The convert program from the Imagemagick package under Linux (or other OSes) cannot convert any formats directly into the Canon RAW format, it is only capable to read (R) them... So it can do the opposite of what the OP is searching for: to convert RAW to whatever.

convert -list format | grep Canon
      CR2  DNG       r--   Canon Digital Camera Raw Image Format
      CRW  DNG       r--   Canon Digital Camera Raw Image Format

But Imagemagick is even a scripting/programming language. Once that you have access to the single pixel values you may save them as you want... programming it. But you need to know the specifications of the desired format.

Moreover, since it is an open source program, you can see in the code the routines used to convert from RAW into whatever and see if you are able to invert them.

On the irreversibility of RAW to JPEG conversion.

This happens for many reasons. Among them:

  • Some formats are lossy, JPEG is usually one of them. You save space at the cost of artifacts and a general modification of the original values for individual pixels.

  • In the classic JPEG format there are only 8 bits for color (it means 256 shades). In a CCD sensor usually the couters are of 12 or 14 bits (that means 4096 and 16384 shades).
    If you think of your image as a histogram, you are going to average in a single bin (column) of the JPEG image, the values that are contained in 16 and 64 bins in the 12 and 14 bits counters respectively. How can you restore individual bin values from the average?

  • Even if your JPEG is in the recent 12-14-16 bit format (JPEG_XT), you are not aware of the algorithm used for this transformation inside the camera.
    (In simple terms, the sensor can have a non-linear efficiency curve. The manufacturer can take this into account by transforming the number from RAW format to a linear shade level in the JPEG, TIFF, ..., format.)

  • The geometry of the CCD is different from the geometry of an image. Roughly speaking, in the images we have a pixel with 3 or 4 values relative to the exact same geometric square. All squares are adjacent.

    In the CCD instead we have geometrically separated sensors sensitive to different wavelengths, again speaking roughly for the R, G, B values. These sensors may or may not have the same surface, and certainly have a different efficiency which, among other things, changes according to the number of counts per second.

    How these RGB sensor sequences are aligned and spaced from each other depends on the design of the CCD. You can see some examples of Color filter array on internet.

    enter image description here Image from Wikipedia

    enter image description here Image from Ephotozine

    How the values of the counts of the red sensors translate, for example, into an image value of a pixel R, depends on their geometric position and on the algorithm chosen which may or may not also take into account the values of nearby sensors, either of those sensitive to the same as to other wavelengths.

    All of these things are hardly reversible.

3

You can not do that.

You have to save as raw from the camera.

Once it is in JPEG format it would be like removing the cream from your coffee to try to make it a raw file.

8
  • 1
    That's simply not true. If the formats are known you can surely convert them. (It seems obvious to me but I'll state it explicitly to avoid misunderstandings: You cannot recover information that is not present in the source format. But that is self-understood, I hope.) By the way, I do not understand your metaphor. Jan 27, 2021 at 19:38
  • Pour cream in your coffee. Stir. Then try to separate the cream and the coffee. Feb 16, 2021 at 17:56
  • Just so that I understand you better: You are using a metaphor of cream and coffee. What in the raw/jpeg problem corresponds to the cream, and what to the coffee? Feb 16, 2021 at 19:30
  • the point is once you change to jpeg from raw you can not go back to raw as there were unfixable changes done to the image. Feb 17, 2021 at 0:51
  • Obviously you cannot reconstruct the original image; but you surely can change the format. You still have not explained your metaphor. Feb 17, 2021 at 8:18
2

As others pointed out, there's no way to get the usual RAW format benefits when converting from JPG.

However, with Canon Powershot it's possible to use a custom firmware from CHDK project that makes it possible to take RAW images. Of course this won't help with existing images.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .