MATLAB: How to apply an ICC profile from one image to another image

icciccreadiccwriteMATLABprofiletiff

I want to get the ICC profile from a WSI image (.svs format) and apply it to a TIFF image.
However, when I used "iccwrite" to do this, it corrupted my TIFF image instead:
>> P = iccread('image1.svs');
>> iccwrite(P, 'image2.tif');
>> imread('image2.tif')
Error using imread (line 362)
Unable to determine the file format.

Best Answer

"iccread" can read independent/standalone profiles and also the profiles embedded in TIFF files. However, "iccwrite" can only write a standalone profile file.
In order to apply the ICC profile you have from image1 to image2, you can follow the following workflow instead:
1. Save the ICC profile from the SVS file:
>> P = iccread('image1.svs');
2. Create a temporary ICM file (for use in step 3):
>> iccwrite(P, 'temporary.icm');
3. Now that you have an ICM file from the SVS file you had, you can apply this to your TIFF image using the workflow described in the following documentation: