Skip to main content

Raw camera files

7 replies [Last post]
navinkjha
Offline
Joined: 2004-12-28
Points: 0

I need to generate thumbnails from raw camera files(jpg).
I have the following questions:
1. Do all cameras support embedded thumbnails?
2. What's the fastest way to generate thumbnails ?
3. Is there a good resource for Java Image APIs ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Fabrizio Giudici

On Aug 3, 2006, at 21:57 , jai-imageio@javadesktop.org wrote:

> I need to generate thumbnails from raw camera files(jpg).

I suppose that you're asking how to extract jpg thumbnails which are
usually embedded
in camera raw files, right?

> I have the following questions:
> 1. Do all cameras support embedded thumbnails?

Not all. And the quality of thumbnails changes greatly, as some
cameras support 1/4,1/2
or even full size thumbnails with excellent quality, others only much
smaller thumbnails.

> 2. What's the fastest way to generate thumbnails ?
> 3. Is there a good resource for Java Image APIs ?

jrawio (jrawio.dev.java.net) is a Java Image I/O API plugin which
supports a number of
camera raw files. Since it's an opensource effort and, as you
probably know, there's no
official specifications of camera raw files, it does not support all
models. jrawio relies
upon users to submit issues about problems and possibly to provide
problematic sample files.

It is currently in 1.0.RC5 stage. To read a thumbnail, you just need
to use the standard Java Image I/O API: BufferedImage thumb =
imageReader.readThumbnail(0, 0)

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
http://www.tidalwave.it/blog - Fabrizio.Giudici@tidalwave.it
mobile: +39 348.150.6941 - fax: +39 027.005.105.36

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

navinkjha
Offline
Joined: 2004-12-28
Points: 0

Hi Fabrizio,

So not all camera files have embedded thumbnails. I am guessing if it does that would be the fastest way to display thumbnail rather than generating one from the high resolution image.

I found ImageIO.read() to be very slow for jpgs, would you agree with that ? I need to display thumbnails as quickly as possible thats why I am trying to make sure I use the right way to get the thumbnail.

Thanks for the pointer to Image I/O plugin. I will look into that site.

-Navin

Fabrizio Giudici

On Aug 4, 2006, at 16:32 , jai-imageio@javadesktop.org wrote:

> Hi Fabrizio,
>
> So not all camera files have embedded thumbnails. I am guessing if
> it does that would be the fastest way to display thumbnail rather
> than generating one from the high resolution image.
>
> I found ImageIO.read() to be very slow for jpgs, would you agree
> with that ? I need to display thumbnails as quickly as possible
> thats why I am trying to make sure I use the right way to get the
> thumbnail.
>
> Thanks for the pointer to Image I/O plugin. I will look into that
> site.

Unfortunately, creating a thumbnail from the hires can't be quick,
because camera raw files require a lot of processing (maybe one could
design
a quick-and-dirty algorithm for generating smaller-size thumbnails as
you don't need all the details - I'm thinking e.g. of demosaicing,
which is one
of the most CPU expensive operations, and that could performed in a
quicker way).

If not all cameras embed usable thumbnails, most of them do. I would
suggest an "adaptive" approach, trying to use the thumbnail if it
exists,
and guessing some trick for the cases in which it doesn't exist.

About the ImageIO.read() slowness, I can't comment as I found out
that "slow" and "fast" often have different meanings for different
people :-)
Up to now I didn't have problems, but I don't need ultra-fast speed
at the moment. How many megapixels per second do you need to read?

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
http://www.tidalwave.it/blog - Fabrizio.Giudici@tidalwave.it
mobile: +39 348.150.6941 - fax: +39 027.005.105.36

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

navinkjha
Offline
Joined: 2004-12-28
Points: 0

Hi Fabrizio,

The system I am working on deals with photos from professional photographers so I am hoping it is high end cameras and so hopefully the thumbnail already
exists. what do mean when you say a quick and dirty thumbnail generation ?

I did a quick test for ImageIO.read() versus Toolkit.getImage(). something like this.

---------------------------------------------------------------------------------------------------------

for ( File imageFile : imageFiles )
{

thumbHolder[ i++ ].setIcon ( new ImageIcon(toolkit.getImage(imageFile.getAbsolutePath()).getScaledInstance(128, 128, Image.SCALE_FAST)));

}

---------------------------------------------------------------------------------------------------------

for ( File imageFile : imageFiles )
{

thumbHolder[ i++ ].setIcon ( new ImageIcon ( ImageIO.read (
imageFile ).getScaledInstance ( 128 ,
128 , Image.SCALE_FAST ) ) ) ;
}

---------------------------------------------------------------------------------------------------------

thumbHolder is JLabel.

The Toolkit method was a lot faster. I am using Java version 1.5_05.

-Navin

Fabrizio Giudici

On Aug 4, 2006, at 18:36 , jai-imageio@javadesktop.org wrote:

> Hi Fabrizio,
>
> The system I am working on deals with photos from professional
> photographers so I am hoping it is high end cameras and so
> hopefully the thumbnail already
> exists. what do mean when you say a quick and dirty thumbnail
> generation ?

AFAIK, demosaicing is one of the more expensive operations, as the
best algorithms (see for instance http://en.wikipedia.org/wiki/
Demosaicing)
as the Variant Number of Gradients and Adaptive Homogeneity-directed
try to extract as many details as possible keeping the same number of
pixels and reducing the number of artifacts. The point of demosaicing
is that the raw image has pixels arranged in a Bayer array as

RG
GB

that is only one channel per pixel is available and other channels
should be interpolated.

If you need to create thumbnails that are smaller than half of the
image, you can first generate a half-size image by collapsing a 2x2
Bayer array
into a single pixel, just reading the R and B samples and averaging
the two greens. I've never tried this, but I would bet some money
that this
approach is much faster, at least by a magnitude.

>
> I did a quick test for ImageIO.read() versus Toolkit.getImage().
> something like this.
>
> ----------------------------------------------------------------------
> -----------------------------------
>
> for ( File imageFile : imageFiles )
> {
>
> thumbHolder[ i++ ].setIcon ( new ImageIcon
> (toolkit.getImage(imageFile.getAbsolutePath()).getScaledInstance
> (128, 128, Image.SCALE_FAST)));
>
> }
>
> ----------------------------------------------------------------------
> -----------------------------------
>
> for ( File imageFile : imageFiles )
> {
>
>
> thumbHolder[ i++ ].setIcon ( new ImageIcon
> ( ImageIO.read (
> imageFile ).getScaledInstance ( 128 ,
> 128 , Image.SCALE_FAST ) ) ) ;
> }

It could be related more to the getScaledInstance() than on the
actual loading. I've seen that there can be HUGE differences in
scaling operations
depending on the pixel sample model. For instance, if I take e.g. a
3800x2500 image with a SinglePixelPackedSampleModel and apply an
AffineTransformOp
scaling down the image to 1000x700, my MacBook Pro running Windows or
Linux takes about 70msec. If I try the same with a
PixelInterleavedSampleModel,
the CPU goes to 100% and after some minutes the operation is not
completed yet (there is not apparent difference in performance under
Mac OS X).
BTW, if I remember well this is a known bug - but also not
considering bugs, I expect performance difference with two different
sample models.

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
http://www.tidalwave.it/blog - Fabrizio.Giudici@tidalwave.it
mobile: +39 348.150.6941 - fax: +39 027.005.105.36

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

navinkjha
Offline
Joined: 2004-12-28
Points: 0

Thanks for all the information. This is really useful I did get a chance to look at the raw camera files project. Looks exciting.

One last question had for you was about readin thumbnails. I used the follwign sample code to read embedded thumbnail but it does not work. Was hoping you you could tell me why.

---------------------------------------------------------

for (File imageFile : imageFiles) {
Iterator itr = ImageIO.getImageReadersByFormatName ("JPG");
ImageReader reader = itr.next() ;
ImageInputStream iis = ImageIO.createImageInputStream (imageFile);
reader.setInput(iis , true);
if (reader.hasThumbnails(0))
thumbHolder[i++].setIcon (new ImageIcon ( reader.
readThumbnail (0 , 0)));

}

-------------------------------------------------------

The camera model is : Canon EOS 20D

The hasThumbnail() method returns false. If I use read(0) method I am able to read the actual jpg.

Fabrizio Giudici

On Aug 11, 2006, at 20:42 , jai-imageio@javadesktop.org wrote:

> Thanks for all the information. This is really useful I did get a
> chance to look at the raw camera files project. Looks exciting.
>
> One last question had for you was about readin thumbnails. I used
> the follwign sample code to read embedded thumbnail but it does not
> work. Was hoping you you could tell me why.
>
> ---------------------------------------------------------
>
> for (File imageFile : imageFiles) {
> Iterator itr = ImageIO.getImageReadersByFormatName
> ("JPG");
> ImageReader reader = itr.next() ;
> ImageInputStream iis = ImageIO.createImageInputStream (imageFile);
> reader.setInput(iis , true);
> if (reader.hasThumbnails(0))
> thumbHolder[i++].setIcon (new ImageIcon ( reader.
> readThumbnail (0 , 0)));
>
> }
>
> -------------------------------------------------------
>
> The camera model is : Canon EOS 20D
>
> The hasThumbnail() method returns false. If I use read(0) method I
> am able to read the actual jpg.
> [Message sent by forum member 'navinkjha' (navinkjha)]
>
> http://forums.java.net/jive/thread.jspa?messageID=142256

Well, keeping always in mind that there are bugs floating around, I'd
say that in this case the problem is different.
Looks like you're forcing the reader to be a JPEG one with
ImageIO.getImageReadersByFormatName ("JPG"):
in other words, you aren't using jrawio readers. Since many camera
raw formats are variants around TIFF, I suppose
that the standard JPEG reader is able to extract the thumbnail
thinking that it's the main image.

I'm asking you if you can add a

System.err.println("READER CLASS:" + reader.getClass());

in your code: in this way we can discover if my theory is correct.

To fix itm you should replace "JPG" with "CR2" or "CRW" (I don't
remember by heart which format the EOS 20D uses).
BTW, the EOS 20D is not in the list of supporter models, as I don't
have any sample from that camera. I'd ask you
if you can provide me with a sample for including in the test suite.

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
http://www.tidalwave.it/blog - Fabrizio.Giudici@tidalwave.it
mobile: +39 348.150.6941 - fax: +39 027.005.105.36

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net