Author |
Topic |
|
whisper1980
USA
83 Posts |
Posted - Feb 22 2021 : 15:40:12
|
I use ImageEnView to scale and recompress jpg images. I default to a 640 pixel width, JPEG_Quality of 80 and the ResampleFilter of Lanczos3.
A customer has both normal camera (Nikon) images and Infrared camera (FLIR) images. The IR jpg images scale down to about 1MB and the standard camera jpg scale down to about 70KB. This seems a bit odd and I don't know why the IR images are more than 10x the size of a normal scaled image (I don't yet know the size of the original image which I am trying to get from the customer)
Details on both show they are both 657x497, 24 bit depth. Standard image is 96dpi, IR is 72dpi. The only other difference based on the Windows details on an image is that the normal image has a compressed bits/pixel of 2 and the IR image shows nothing for that property.
Could this be the reason the IR image is so much larger than a standard camera image? If so, what ImageEnView.IO.Params would I use to produce the same value. I see SamplesPerPixel and BitsPerSample, but don't know if those will help.
Thoughts?
Eric |
|
xequte
38690 Posts |
Posted - Feb 22 2021 : 21:51:32
|
Hi Eric
(Excluding the rare case of gray-scale JPEG images) JPEG images are always full color, so playing with the bit depth is unlikely to have any meaningful effect.
The only factors for JPEG file size are: - JPEG quality (including to a lesser extent, DCT method and Smoothing) - Image dimensions - Image content (uniformity of colors in particular)
Nigel Xequte Software www.imageen.com
|
|
|
whisper1980
USA
83 Posts |
Posted - Feb 23 2021 : 13:07:21
|
Something weird about the pictures taken with the FLIR infrared camera. I can use Paint.Net to load and save a 1.2MB FLIR jpg image as a BMP, and it is smaller, only 958KB. I can then save the BMP as a JPG with 100% quality and it is 224KB.
I can even skip the BMP conversion and just save the 1.2MB jpg image as a new JPG image, 100% quality, 4:2:2 chroma subsampling, and it is only 226KB. Saving it at 80% quality like I do in my app with ImageEN, the file is only 72KB, very much like the normal camera app images scale down to.
So I do not know what is going on with FLIR images, but Paint.Net does something different. All the values appear to be the same betweem the 1.2MB and 72KB images when looking at the Details tab for an image in Windows. Plus the images all look the same visually.
Any wild guesses on how to do whatever Paint.Net might be doing differently than ImageEn. I suppose you would need sample code to see what I'm doing in order to make a reasonable guess. I can send you the 1.2MB image if you want.
Eric |
|
|
xequte
38690 Posts |
Posted - Feb 23 2021 : 15:48:34
|
Unfortunately I am unfamiliar with Paint.net. It sounds like it is doing some further processing behind the scenes when saving.
Nigel Xequte Software www.imageen.com
|
|
|
whisper1980
USA
83 Posts |
Posted - Feb 23 2021 : 18:11:50
|
FWIW, our old version of the program uses the old GR32, and it scales it right down to 56KB using about the same settings, 640 width, 80% quality and Lanczos resampler. For grins I also tried loading and saving the image as a new jpg using Windows Paint and it didn't make it smaller, but Snagit did (52KB).
Eric |
|
|
whisper1980
USA
83 Posts |
Posted - Feb 23 2021 : 19:24:26
|
From what I've read, FLIR jpg images are actually "radiometric jpeg images" and contain Radiometric data (i.e. temperature data) embedded in each pixel. https://flir.custhelp.com/app/answers/detail/a_id/1729/~/radiometric-jpeg-images
I think this is what is keeping the images large. So, with that in mind I added the following hack to my image import code and it takes care of the problem (the FLIR images down nicely as expected). I just hope to find a way to know if this data is present, maybe by reviewing the EXIF data so I don't have to do this for every jpg image I import.
If you know of a more efficient way to do this, it would be welcomed. I'm thinking it will lose the orientation data which is not good.
var vJpg := TJPEGImage.Create;
try
vJpg.LoadFromFile(pFilename);
var vBmp := TBitmap.Create;
try
vBmp.Width := vJpg.Width;
vBmp.Height := vJpg.Height;
vBmp.PixelFormat := pf24bit;
vBmp.Canvas.Draw(0, 0, vJpg);
vJpg.Assign(vBmp);
var vStream := TMemoryStream.Create;
try
vJpg.SaveToStream(vStream);
vStream.Position := 0;
vImageEnView.IO.LoadFromStreamJpeg(vStream);
finally
FreeAndNil(vStream);
end;
finally
FreeAndNil(vBmp);
end;
finally
FreeAndNil(vJpg);
end;
Eric |
|
|
whisper1980
USA
83 Posts |
Posted - Feb 24 2021 : 09:52:16
|
This is what I ended up doing to remove the radiometrics. I tried a bunch of things, and this seemed the simplest and maintained the orientation even though I lose EXIF data (which I don't really need after the conversion, but might be nice to keep). If you have a better idea, let me know! :)
IEGlobalSettings().IOParamDefaults.EnableAdjustOrientation := true;
...
vImageEnView.IO.LoadFromFile(pFilename);
var vFileType := vImageEnView.IO.Params.FileType;
var vMake := String(vImageEnView.IO.Params.EXIF_Make);
var vModel := String(vImageEnView.IO.Params.EXIF_Model);
if (vFileType = ioJpeg) and (vMake.StartsWith('FLIR', true) or vModel.StartsWith('FLIR', true)) then
begin
var vStream := TMemoryStream.Create;
try
vImageEnView.IO.SaveToStreamBMP(vStream);
vStream.Position := 0;
vImageEnView.IO.LoadFromStreamBMP(vStream);
finally
FreeAndNil(vStream);
end;
end;
Eric |
|
|
xequte
38690 Posts |
|
whisper1980
USA
83 Posts |
Posted - Feb 24 2021 : 17:23:27
|
Well, that was a lot easier and much cleaner! I wish I knew about that a few hours/days ago, lol. I did a ContainsInfo and it came back with [ierEXIF, ierJPEGMarkers]. Since I wanted to keep the EXIF data I issued ResetInfo([ierJPEGMarkers]) which takes care of it.
Resetting jpeg markers won't affect normal jpg images?
Thanks!
Eric |
|
|
xequte
38690 Posts |
Posted - Feb 24 2021 : 19:06:01
|
Sorry Eric,
I didn't click earlier that this was a meta-data issue. Usually meta-data is quite small.
It's hard to say what data is lost when stripping JPEG markers because it can be custom, but I'd be surprised if you lost anything that was missed.
Nigel Xequte Software www.imageen.com
|
|
|
whisper1980
USA
83 Posts |
Posted - Feb 25 2021 : 12:44:57
|
No worries. It is always a learning experience trying to figure out how to solve a problem. I did learn a few things, so all good!
Eric |
|
|
|
Topic |
|