Stain Normalization for Histology Images

I’m trying out the stain normalization toolbox provided by the Department of Computer Science over at Warwick . Be fair warned, it’s a windows only, matlab, toolbox.

 

All in all, things seem to be going well after a bit of tweaking. The demos that they provide have a few caveats though which took a while to figure out:

  1. Since I assume the underlying executable relies on the bundled opencv dlls (which do not support multi-threaded access), parallelizing multiple image normalizations is a no go. I attempted to do this in matlab using a simple parfor loop and needless to say, things did not end well
  2. The output from the executable is literally the same name as provided in the filename.txt except in the “normalized” sub-directory (need to pre-create if it doesn’t exist). This is a bit of a bummer because one would expect to be able to use absolute filenames  and use “c:\dir1\dir2\filename1.tif” in the filename.txt. But after running the program attempts to save output into “.\noramalised\c:\dir1\dir2\filename1.tif”, which obviously isn’t going to fly.
  3. Since the executable requires all of the bundled libraries to be in the same path, as well as local filenames (see #2 above),  it just seemed easier to copy the files I wanted to normalize to that directory, perform the normalization and then delete them afterwords.

So taking those 3 things into account, I have this basic matlab script (below) which acts at the workhorse, wrapping around the .zip file provided at the url above.

It works quite well but is limited to usage on H&E images as their bundled H&E color model file seems to be in a proprietary binary format. I’ll be publishing our results soon which show how our approach is comparable in most cases, but seems to better in more extreme cases. Stay tuned!
 

Code Available here.

 

  1. templateImage_fname='template.tif';
  2. toolbox_location='C:\Research\code\stain_normalization_toolbox';
  3.  
  4. copyfile(templateImage_fname,toolbox_location);
  5.  
  6. ppwd=pwd;
  7.  
  8. files=dir('*.tif');
  9.  
  10. fid = fopen( 'filename.txt', 'w+' );
  11. for fi=1:length(files)
  12.     fname=files(fi).name;
  13.     copyfile(fname,toolbox_location);
  14.     fprintf(fid, '%s\n', fname);
  15. end
  16. fclose(fid);
  17.  
  18. movefile('filename.txt',toolbox_location);
  19.  
  20. cd(toolbox_location)
  21.  
  22. to_run=sprintf('ColourNormalisation.exe BimodalDeconvRVM filename.txt %s HE.colourmodel',templateImage_fname);
  23. dos(to_run);
  24.  
  25. delete('*.tif');
  26.  
  27. cd (ppwd)

4 thoughts on “Stain Normalization for Histology Images”

  1. Agree with the previous comment!

    Yea, bummer that the usage is limited. I’m wondering how they constructed the color model. Probably it’s based on the first half of the paper. I think the binary file is only doing the mapping between 2 images.

    Well, I hope to see your tool soon, and good luck with the publication!

  2. On the authors webpage ( enlace ) is the 2nd version of the toolbox (Published this month). It seems that now is possible to build the color specification model.

Leave a Reply

Your email address will not be published. Required fields are marked *