[GIL] rotated90cw_view - jpeg lossless rotation
I rotate jpeg photos to portrait by reading the file and saving it like this: boost::gil::jpeg_write_view(file, boost::gil::rotated90cw_view(boost::gil::view(img))); results: original size: 4106172 image/jpeg 3264 2448 rotated size: 5594681 image/jpeg 2448 3264 The rotation should be lossless (as the image is a multiple of the jpeg MCU) but the size has increased significantly and the exif tags disappeared. My questions: Has it been tested that the rotation is lossless ? What can I do make sure the exif tags are preserved ? thanks jose
Hi Jose,
On 12/6/09 2:10 AM, "Jose"
Has it been tested that the rotation is lossless ?
Rotation is lossless, but the jpeg format is not. There is a quality setting in the jpeg parameters that affects file size. I believe the new jpeg IO that Christian wrote exposes that setting, Christian is that true?
What can I do make sure the exif tags are preserved ? Christian, is this possible?
Lubomir
Hi all,
Rotation is lossless, but the jpeg format is not. There is a quality setting in the jpeg parameters that affects file size. I believe the new jpeg IO that Christian wrote exposes that setting, Christian is that true?
Yes.
What can I do make sure the exif tags are preserved ? Christian, is this possible?
Good question. I think libjegp provides several lossless transformations while reading an image. This is not part of the current new gil::io. I'll investigate how hard it might be to add such feature. Christian
On Sun, Dec 6, 2009 at 4:50 PM, Lubomir Bourdev
Rotation is lossless, but the jpeg format is not.
Lossless rotation is supported libjpeg release 7 (2005), but most Linux systems I have check come with version 6. http://jpegclub.org/jpegtran/ Using GIL original size: 4106172 image/jpeg 3264 2448 rotated size: 5594681 image/jpeg 2448 3264 Using jpegtran -rot 90 -perfect 4106172 image/jpeg 3264 2448 4073598 image/jpeg 2448 3264 Note that jpegtran also removes exif tags, but if not the size would be the sime (as I understand lossless transform).
There is a quality setting in the jpeg parameters that affects file size. I believe the new jpeg IO that Christian wrote exposes that setting, Christian is that true?
The current GIL already has a quality parameter (third param of jpeg_write_view) but for the above GIL experiment I assumed default quality=100 so that no loss was introduced by change in quality.
What can I do make sure the exif tags are preserved ? Christian, is this possible?
Another option is to keep the original photo as it is and rotate before resampling (but I couldn't compile it). What type magic am I missing ? TYPE myview = boost::gil::rotated90cw_view(boost::gil::view(img); boost::gil::resample_pixels(myview, boost::gil::view(fin), mat, bg::bilinear_sampler()); boost::gil::jpeg_write_view(file_out, boost::gil::const_view(fin), quality); thanks
Hi Jose, please see comments below.
On Sun, Dec 6, 2009 at 5:10 AM, Jose
I rotate jpeg photos to portrait by reading the file and saving it like this:
boost::gil::jpeg_write_view(file, boost::gil::rotated90cw_view(boost::gil::view(img)));
results:
original size: 4106172 image/jpeg 3264 2448 rotated size: 5594681 image/jpeg 2448 3264
The rotation should be lossless (as the image is a multiple of the jpeg MCU) but the size has increased significantly and the exif tags disappeared.
I think libjpeg has a way of applying lossless transformations while reading it. Is that correct, or am I mistaken here? How do you preserve the exif tags? Does a user has to read them separately and cache them? In the new io extension there is the image_write_info structure which would allow a user to pass additional information when writing images. I would be more then willing to add functionality to the new gil::io. Can you provide a small libjpeg example? I'll also have a look at jpegtran.
My questions:
Has it been tested that the rotation is lossless ? What can I do make sure the exif tags are preserved ?
Good questions ;-) I'll investigate.
thanks jose
Christian PS: I see there is still one email from you I need to answer. Will do that later on.
Christian Henning wrote:
Hi Jose, please see comments below.
On Sun, Dec 6, 2009 at 5:10 AM, Jose
wrote: I rotate jpeg photos to portrait by reading the file and saving it like this:
boost::gil::jpeg_write_view(file, boost::gil::rotated90cw_view(boost::gil::view(img)));
results:
original size: 4106172 image/jpeg 3264 2448 rotated size: 5594681 image/jpeg 2448 3264
The rotation should be lossless (as the image is a multiple of the jpeg MCU) but the size has increased significantly and the exif tags disappeared.
I think libjpeg has a way of applying lossless transformations while reading it. Is that correct, or am I mistaken here?
JPEG lossless transformation is a trick performed on the compressed JPEG data (IIUC, you basically shuffle the values in each block), and can therefore not be achieved by using a generic image library that provides a JPEG reader and writer. You need specialized functions that operate on the compressed JPEG data. Sebastian
On Sun, Dec 6, 2009 at 5:13 PM, Sebastian Redl
I think libjpeg has a way of applying lossless transformations while reading it. Is that correct, or am I mistaken here?
JPEG lossless transformation is a trick performed on the compressed JPEG data (IIUC, you basically shuffle the values in each block), and can therefore not be achieved by using a generic image library that provides a JPEG reader and writer. You need specialized functions that operate on the compressed JPEG data.
Sebastian
Maybe. Then it would make sense to support this by wrapping the jpeg7 function jtransform_perfect_transform
participants (4)
-
Christian Henning
-
Jose
-
Lubomir Bourdev
-
Sebastian Redl