ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Jpg Compression question

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
whisper1980 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
10   L A T E S T    R E P L I E S    (Newest First)
whisper1980 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
xequte 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 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 Posted - Feb 24 2021 : 16:36:10
Hi Eric

The upshot of your method seems to be just keeping the image data. This implies the excess size is due to embedded meta-data.

Does resetting it make any difference:

https://www.imageen.com/help/TIOParams.ResetInfo.html

Nigel
Xequte Software
www.imageen.com
whisper1980 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
whisper1980 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 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
xequte 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 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 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