ijp-dcraw
provides ImageJ plugin "DCRaw Reader" to open raw images from digital cameras. Originally the backend was
provided by dcraw tool. Current versions is using LibRaw/dcraw_emu
tool. The hundreds of supported cameras are
listed on LibRaw Supported Cameras page.
There are two plugins:
- DCRaw Reader - reads images in camera raw format
- DCRaw Identify - provides info about the raw image, like camera make and metadata contained in the raw file
- DCRaw Unprocessed - reads mostly unprocessed raw image, it may be still before demosaicing. You may need a plugin like ijp-DeBayer2SX to convert it to a color image.
ijp-dcraw
distribution, available from Releases page, provides native binaries for Windows and macOS. Binaries for
other
system can be added manually.
By default, the "DCRaw Reader" plugin looks for the dcraw_emu
and raw-identify
executables in the
subdirectory dcraw
of ImageJ plugins folder.
Alternative location can be specified by one of:
- Setting Java system property
dcrawExecutable.path
,raw-identifyExecutable.path
, andunprocessed_rawExecutable.path
to location of thedcraw
,raw-identify
, andunprocessed_raw
executables, for instance:
-DdcrawExecutable.path=bin/dcraw_emu.exe -Draw-identifyExecutable.path=bin/raw-identify.exe
- or adding property
.dcrawExecutable.path
to ImageJ properties fileIJ_Props.txt
. Note period at the beginning of property name, it is required by ImageJ. Example line that should be added toIJ_Props.txt
.dcrawExecutable.path=C:/apps/bin/dcraw_emu.exe
.raw-identifyExecutable.path==C:/apps/bin/raw-identify.exe
.unprocessed_rawExecutable.path==C:/apps/bin/unprocessed_raw.exe
- Download
ijp-dcraw_plugins_*_win_macos.zip
from the Releases page. Binaries, taken from the LibRaw release are provided for Windows and macOS. - Unzip to ImageJ plugins directory. By default, the DCRaw Reader looks for the
dcraw_emu
andraw-identify
executables in the subdirectory "dcraw" of the ImageJ plugins folder. - Restart ImageJ
The plugin installs under Plugins
> Input-Output
> DCRaw Reader...
.
- ijp-color Contains plugin IJP Color Calibrator that can be used to color calibrated raw images. For instance, it works well with "16-bit linear" images.
- ijp-DeBayer2SX an alternative way to demosaic raw images
If you wander what is going on behind the scenes, how dcraw_emu
executable is used, you can see the exact command line
ij-dcraw is executing by turning on the "Debug Mode". Select in ImageJ menu: "Edit" > "Options" > "Misc" and select "
Debug Mode". Now open an image using DCRaw Reader and watch the Log window, it will show the command line with the
options used and the output log generated by dcraw_emu
.
DCRaw offers a couple of options for applying white balance to processed raw image. In the backend they are implemented as separate options. In the front end we try to bring some consistency and clarity. The front end provides following white balance options:
- Disable - force not to use any white balance - all channels are scaled the same way. This is the same as command
line option
-r 1 1 1 1
(white balance multiplier set to 1 for all channels). This useful to for best preservation of the raw image data, for instance, when multiple images need to be compared. - Derived - white balance multipliers are derived from the color conversion matrices embedded in the raw image
metadata. This is done without utilizing the information about camera recorded white balance. This is the default
behaviour of DCRaw. This option was in the past called "None". The name was changes as could indicate all channels
have the same multipliers. You can see what are the channel multipliers using the "Raw Identify" with the "verbose"
option. In the output look to an entry named "Derived multipliers". It maybe at the very end of the output and look
something like this:
This may recover manufacturers "default white balance" for the camera, but in some cases may lead to issues, like image saturation (in example above the red channel is multiplied significantly more than other channels and may get saturated for bright pixels)
Derived D65 multipliers: 2.441519 0.995024 1.658339
- Camera - use white balance coefficients recorded by the camera. They also can be seen using the "Raw Identify" plugin.
- Averaging - compute white balance multiplier by averaging the entire image.
Example of using "DCRaw Reader" plugin from an ImageJ macro. The macro converts all images in an input directory, assumed to be some supported raw format, to TIFF saved in the output directory. The source code for the macro is located in macros/Batch_convert_dcraw.ijm.
//Get File Directory and file names
dirSrc = getDirectory("Select Input Directory");
dirDest = getDirectory("Select Output Directory");
fileList = getFileList(dirSrc);
caption = "dcraw batch converter";
print(caption + " - Starting");
print("Reading from : " + dirSrc);
print("Writing to : " + dirDest);
// Create output directory
File.makeDirectory(dirDest);
setBatchMode(true);
fileNumber = 0;
while (fileNumber < fileList.length) {
id = fileList[fileNumber++];
print(toString(fileNumber) + "/" + toString(fileList.length) + ": " + id);
// Read input image
run("DCRaw Reader...",
"open=" + dirSrc + id + " " +
"use_temporary_directory " +
"white_balance=[Camera white balance] " +
// "do_not_automatically_brighten " +
"output_colorspace=[sRGB] " +
"read_as=[8-bit] " +
"interpolation=[DHT] " +
// "half_size " +
// "do_not_rotate " +
"");
idSrc = getImageID();
// Save result
saveAs("Tiff", dirDest + id);
// Cleanup
if (isOpen(idSrc)) {
selectImage(idSrc);
close();
}
}
print(caption + " - Completed");
Example of using DCRawReader
API from a Java code. The source code is located
in src/test/java/demo/DCRawReaderDemo.java.
import ij.ImagePlus;
import ij_plugins.dcraw.DCRawException;
import ij_plugins.dcraw.DCRawReader;
import java.io.File;
class DCRawReaderDemo {
public static void main(String[] args) throws DCRawException {
final File inFile = new File("../test/data/IMG_5604.CR2");
final ImagePlus imp = new DCRawReader().read(inFile);
}
}
You can also call dcraw
by passing command line options. This may give access to some functionality
that may not be yet exposed through higher level DCRawReader
API.
import ij.IJ;
import ij.ImagePlus;
import ij_plugins.dcraw.DCRawException;
import ij_plugins.dcraw.util.ExecProxy;
import java.io.File;
import java.util.Optional;
import static ij_plugins.dcraw.IJPUtils.isBlank;
/**
* Example of calling dcraw executable directly, passing command native line options
*/
public class DCRawExecProxyDemo {
public static void main(String[] args) throws DCRawException {
// Input file
final File inFile = new File("../test/data/IMG_5604.CR2");
// Output file that will be generated by dcraw
final File outputFile = new File(inFile.getAbsolutePath() + ".tiff");
// dcraw wrapper
final ExecProxy proxy = new ExecProxy("dcraw_emu", "dcrawExecutable.path",
Optional.of(m -> System.out.println("status: " + m)),
Optional.of(m -> System.out.println("error : " + m)));
// Execute dcraw
ExecProxy.Result r = proxy.executeCommand(new String[]{
"-v", // Print verbose messages
"-q", "0", // Use high-speed, low-quality bilinear interpolation.
"-w", // Use camera white balance, if possible
"-T", // Write TIFF instead of PPM
"-j", // Don't stretch or rotate raw pixels
"-W", // Don't automatically brighten the image
inFile.getAbsolutePath()});
System.out.println("dcraw_emu stdErr: '" + r.stdErr + "'");
System.out.println("dcraw_emu stdOut:\n" + r.stdOut);
if (isBlank(r.stdErr)) {
// Load converted file, it is the same location as original raw file but with extension '.tiff'
final ImagePlus imp = IJ.openImage(outputFile.getAbsolutePath());
System.out.println("Loaded converted raw file: " + imp.getWidth() + " by " + imp.getHeight());
}
}
}
ijp-dcraw project was originally hosted on SourceForge. Releases 1.5 and older can be found there.