How to Convert Raw Camera Image to JPEG in Linux

Whenever a picture is clicked with a digital camera, the image is stored in a raw format, i.e. without any algorithm run over it, or without any loss of data. Modern cameras do have options to directly export images to a format like JPEG or PNG, but by default, it’s stored as a raw image.

The raw format can differ from camera to camera, and usually cameras of the same brand store the image in the same format. The raw image file is however not suitable when it comes to image processing, storing, or just viewing it on any device. Most operating systems do not by default have software to view raw images. For these reasons, we need to convert the raw image files to well-known image file formats.

Today we will learn how to convert a raw image file to a JPEG file from the Linux command line.

Convert Raw Image to JPEG using ImageMagick

ImageMagick is a quite popular tool for image processing in Linux. It consists of a set of command lines as well as GUI utilities. It installs a tool called ‘convert‘ to convert images to and from a wide array of file formats.

It is available in standard repositories of Linux distributions.

$ sudo apt install imagemagick   [On Debian/Ubuntu & Mint]
$ yum install imagemagick        [On RHEL/CentOS & Fedora]

Once installed, you can verify that the ‘convert‘ tool has been installed.

$ convert -v
Verify Convert Tool
Verify Convert Tool

To convert a raw file, first make sure the raw file name does not contain any file extension. Otherwise, ‘convert‘ will consider a file extension if it is present and will fail if the extension is not supported.

For example, if you have a file called ‘raw_canon.cr2‘, copy it to a file named ‘raw_canon‘ using the cp command.

$ cp raw_canon.cr2 raw_canon

Now we can simply call convert with the following syntax:

$ convert filename_tobe_converted target_filename.target_extension

In our case, this will be:

$ convert raw_canon raw_canon.jpeg

To verify if the file is actually a JPEG file now, use the file command (which will read and analyze the file to determine its type).

$ file raw_canon.jpeg
Verify File Type
Verify File Type

You can obviously also verify this by trying to open the file in an image viewer.

Conclusion

In this article, we have seen how a raw camera image can be converted to JPEG. The raw image in this example is a Canon camera image, however, the same method can be used for other raw images.

Thanks for reading this, and if you know have any issues or thoughts let us know in the comments below!

Got something to say? Join the discussion.