ImageMagick/dcraw convert raw .PEF file to tiff

I’m slowly learning come command line image processing with ImageMagick and I finally figured out how to ouput a “normal” looking tiff from dcraw. (Using the -w option) [Still haven’t figured out how to do it through IM, I just call dcraw directly]

Anyway, that’s all very nice to convert 1 raw file, but I need to convert a whole folder full! How do select more than one file to send to dcraw? The * operater doesn’t work with dcraw.

I’m running Windows 7 64-bit.
Thanks!

Write a bat script that calls a for loop that passes each file separately to dcraw.

Hello, on Linux it goes like so:

$ dcraw -w -T *.PEF

This creates 8-bit tiff files. If you want 16-bit files, says this:

$ dcraw -w -T -6 *.PEF

More about converting raws using dcraw is here:
https://paulsphotopalace.wordpress.com/dcraw-2/

You might want to throw a look at the Handy section as well.

The wildcard * is a bash shell glob, it won’t work in the windows does shell.

Also beware, the does shell has a maximum character limit. I have several bat scripts at work that use imagemagick on win 7, and I generally hit that max length limit when processing between 10 - 20 files at a time

The wildcard * works just fine for ImageMagick, but not dcraw.

Thanks, I basically got all of that, but I take it that Windows doesn’t work the same as Linux, because dcraw says “Invalid argument” when I try the *.

@paperdigits, I haven’t gotten so far as writing bat scripts yet. Is it very difficult?

Is there no “simple” way to process a whole folder of .PEF files? I wish I knew how to call dcraw through IM, because I do know how to do a whole folder with IM!

Maybe try Powershell? I hear it’s pretty good, and it seems to take wildcards.

No go, I get the same error in Powershell. :frowning:

I have heard of shell/CLI that emulate the Linux environment in Windows, would that be something that might work?

The environment I use when I have to use windows is Cygwin. This would probably be the best option if you wanted most of a bash shell available.

But this should be possible using a windows shell. Give me a few minutes and I’ll get you and answer (or at least a batch script).

Basically, what @heckflosse already posted. You can do this:

FOR %a IN (*.PEF) DO dcraw.exe -w -T %a

Hey, thanks a lot! I finally figured it out with help from the stackoverflow thread that @heckflosse linked to. It probably took me half an hour, because I had no idea what the correct syntax was to make dcraw and the FOR command work with each other. Just for future reference, the command that worked for me is:

for %f in (*) do dcraw -w -W -T -6 %f

(That’s what I typed right into the command line, I didn’t actually make a bat file)

I’m really glad to find out that there IS a way to make dcraw see more than one file, even if it has to be slightly complicated. :slight_smile:

1 Like

Note that technically dcraw is still only seeing one file at a time, your shell is making a list of files and passing them one at a time to dcraw.

Also * is shorthand for everything, so if there are other files dcraw can’t do anything with, such as an xmp or jpeg, in the folder, dcraw will probably complain. @patdavid’s *.pef is shorthand for all pef files.

Yeah, I think I understand how that all works now. :slight_smile:

Yep, I created a batch file after posting here, and sure enough, dcraw always complains about it.

Now I have another question… Is it possible to set the filename for the files that dcraw outputs?

It defaults to the same name as the original .PEF file, but I want to rename them to something else, like converted_raw. I found the -O switch which works for 1 file, but when used with the FOR loop, it just overwrites the file with the same name over and over again, instead of creating a new one.

Try -O converted_%f

1 Like

Thanks, that was a step in the right direction! That appends “converted” to the front of the original filename. I guess that would do the trick, but it’s still sort of messy…

Oops, I just realized that it keeps the .PEF file extension too. :frowning: So that’s not really a workable solution, the extension is supposed to be .tiff

EDIT: I found a command that works!

for %f in (*.PEF) do dcraw -w -W -T -6 -O converted_%~nf.tif %f

The ~n tells it to use just the filename, not the extension. See here for documentation: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/for.mspx?mfr=true

Perhaps if you could be a little more forthcoming with what you’d like the file names to be? :slight_smile: Hiow about an example?

Well, I’m not really looking for anything fancy, just something as simple as hugin’s method.

(Set the name you want, [like “converted” for example] and hugin will use that as a prefix and append a number at the end, instead of overwriting the same file over and over.

In hugin I do it like this: -a aligned_ and it names files like this:

  • aligned_0000.tif
  • aligned_0001.tif
  • aligned_0002.tif

and so on…

I only wanted to nudge you in the right direction. I remember discovering the magic of the shell, I didn’t want to rob you of that!

ImageMagick/GraphicsMagick cannot decode and demosaic raw files. Technically if you compiled IM with dcraw/ufraw support you could, but then you’re still just using dcraw and having IM call it.

The bigger question is why are you doing this in the first place? Knowing how to demosaic raw files using dcraw for the sake of knowing is fine, but if you want to get actual photos, why do this? Rather use RawTherapee (it can be used from command-line) to take advantage of its higher quality raw handling than dcraw’s.