Color changes on Resize operation

Discussions about image processing and document imaging.
Post Reply
BCWGuy
Posts: 19
Joined: Fri Jun 03, 2011 8:05 pm

Color changes on Resize operation

Post by BCWGuy » Thu Jun 13, 2013 2:28 pm

Hello again,

I am evaluating the gdPicture 9 components (looking forward to 10 with improved ICC Color profile support), and noticed this issue:

It looks like when an image with an ICC profile is loaded and resized, something strange is happening with the color. For example, look at this Delphi code which loads a JPG, save it right back, then reduces it 1 pixel and saves it again:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  gdPicImg: TGdPictureImaging;
  ImageID: integer;
  NewWidth, NewHeight: integer;
begin
  gdPicImg := TGdPictureImaging.Create( nil );
  ImageID := gdPicImg.CreateGdPictureImageFromFileICM( 'D:\Tmp\ColorTestProfile.jpg' );
  gdPicImg.SaveAsJPEG( ImageID, 'D:\Tmp\ColorTestProfile_Full.jpg');
  NewWidth := gdPicImg.GetWidth( ImageID )-1;
  NewHeight := gdPicImg.GetHeight( ImageID )-1;
  gdPicImg.Resize( ImageID, NewWidth, NewHeight, InterpolationMode_HighQualityBicubic );
  gdPicImg.SaveAsJPEG( ImageID, 'D:\Tmp\ColorTestProfile_AlmostFull.jpg');
  gdPicImg.ReleaseGdPictureImage( ImageID );
end;
The two files output are different, with the resized image looking more saturated. This only seems to be happening with images that have ICC profiles embedded, and at the moment I am only working with AdobeRGB profiles.

This particular image is close, but you see the differences mostly in the reds (like the robot and chart). Some images better demonstrate this difference, but I can't paste those as they are not public domain images.
Image

How can I get the colors to remain consistent under these conditions?

Note that the source image came from http://www.scienceandart.org/photoshop2 ... tA4Ltr.jpg

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Color changes on Resize operation

Post by Loïc » Thu Jun 13, 2013 3:47 pm

Hello,
How can I get the colors to remain consistent under these conditions?
It is technically impossible by using an interpolation algorithm using smoothing effect during the resizing process.
It is also impossible by using JPEG compression scheme that uses color quantization.

So I can suggest 2 approach:

1- Resizing with nearest neighbor interpolation + saving as PNG or TIFF (using lossless compression scheme). Input color fidelity - poor quality.
2- Resizing with HQ bicubic interpolation + saving as PNG or TIFF (using lossless compression scheme). Input color fidelity only when zoom is 100% - high quality.

or maybe also resizing with hq interpolation + saving in JPEG with a quality parameter of 100.

Kind regards,

Loïc

BCWGuy
Posts: 19
Joined: Fri Jun 03, 2011 8:05 pm

Re: Color changes on Resize operation

Post by BCWGuy » Thu Jun 13, 2013 6:42 pm

Thanks for your reply.

While I understand that some color change is going to happen, I still think this is some sort of bug (perhaps in my understanding) in how much change is occurring, and only when ICC profiles are involved:

1) If the images don't contain ICC profiles, the output images are fine.

2) If I used CreateGdPictureImageFromFile instead of CreateGdPictureImageFromFileICM, the output images are fine (as long as they have no profile).

3) My code sample is already using HQ bicubic interpolation, and using the same image quality when saving both images, and I have changed it to 100% JPG quality with no change (there is still a color change).

Could you please run an actual test with the image to see what I mean? The problem is only occurring with ICC profile images, nothing else.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Color changes on Resize operation

Post by Loïc » Thu Jun 13, 2013 7:06 pm

Hello,

As I told you in your other ticket the color correction support is quite partial in V9. In V10 it will be fully implemented.

Find attached your image resized with your code with the V10. For me input and output colors looks exactly the same.
output.jpg
Image resizing with ICC support.
Kind regards,

Loïc

BCWGuy
Posts: 19
Joined: Fri Jun 03, 2011 8:05 pm

Re: Color changes on Resize operation

Post by BCWGuy » Thu Jun 13, 2013 7:22 pm

Thank you for the quick reply, and all the assistance.

When you posted about partial color profile for verison 9 in another thread, I assume you were referring to the ability to convert profiles which was the purpose of that thread. This thread however is not about converting profiles, but leaving colors as-is. I did not realize there was more incompatibility issues in version 9.

In that case, I take it that it is a known issue that version 9 is creating images that, under specific ICC-profile requirements, is saving new files with altered colors once resized. I further hope and assume that version 10 will correct this.

Looking at the JPG you posted, there does not seem to be a color profile embedded, where with my sample code (in version 9), the profile was embedded in the JPG. So I suppose that is one difference between version 10 and 9 (9 was embedding the profile but 10 won't)?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Color changes on Resize operation

Post by Loïc » Thu Jun 13, 2013 7:35 pm

I suppose that is one difference between version 10 and 9 (9 was embedding the profile but 10 won't)?
This is the contrary. V10 keeps the image with the profile while V9 won't.

BCWGuy
Posts: 19
Joined: Fri Jun 03, 2011 8:05 pm

Re: Color changes on Resize operation

Post by BCWGuy » Thu Jun 13, 2013 7:41 pm

Sorry, then I'm confused. The source image from here:
http://www.scienceandart.org/photoshop2 ... tA4Ltr.jpg

Has an AdobeRGB profile.
The JPGs that my above code output using version 9, also had the AdobeRGB profile.
The JPG image you posted, which you created with version 10, have *no* profile.

Unless that JPG is not the actual output, and perhaps you ran it through some other program to reduce it's size, and that other program discarded the profile? In that case, the posted JPG isn't very accurate.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Color changes on Resize operation

Post by Loïc » Thu Jun 13, 2013 7:56 pm

The JPG image you posted, which you created with version 10, have *no* profile.
this is wrong. The image I posted contains the exact same color profile as the input bitmap.

BCWGuy
Posts: 19
Joined: Fri Jun 03, 2011 8:05 pm

Re: Color changes on Resize operation

Post by BCWGuy » Thu Jun 13, 2013 8:10 pm

My apologies, I had downloaded the thumb, and not the image available when you click the image you posted. As you said, that image does have the ICC profile attached.

However, yours was not the resized image, as it was still 2400 pixels high.

My sample code created something called "ColorTestProfile_Full.jpg" which was not sized and had no problem.

My sample code then created something 1 pixel smaller named "ColorTestProfile_AlmostFull.jpg". This is the file that shows the problem. The color change I saw was only when the image was resized (hence the subject line of this thread).

Do you have a version of the ColorTestProfile_AlmostFull.jpg file from version 10?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Color changes on Resize operation

Post by Loïc » Thu Jun 13, 2013 8:41 pm

Attached the resized image with V10 saved as jpeg (q: 100)
output.jpg

BCWGuy
Posts: 19
Joined: Fri Jun 03, 2011 8:05 pm

Re: Color changes on Resize operation

Post by BCWGuy » Thu Jun 13, 2013 9:02 pm

Thank you, that image looks great. So I assume that version 10 will be our big helper.

Just as a side note, as you may have noticed I am excruciatingly detail-oriented: The image you posted was actually larger 2400 pixels, where my code was reducing the dimension by 1. I assume that your code was essentially the same as mine in other aspects such as the loading, resizing, and saving.

Thank you again for your patience and assistance.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests