Last active
August 29, 2015 14:21
-
-
Save jnkather/64249e630b772ec1b22d to your computer and use it in GitHub Desktop.
Analyze colors of histological image in OD space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% (c) Jakob Nikolas Kather 2015 | |
% contact: http://www.kather.me | |
% this code uses a histological image and performs the following steps | |
% - convert to optical density (OD) space (ref: Ruifrok et al. http://www.ncbi.nlm.nih.gov/pubmed/11531144) | |
% - plot image pixels in OD space | |
% - color pixels according to their original color | |
% this script can be used to visualize the color distribution of a given histological image | |
% get source image | |
imageURL = 'myImage.png'; % tested with images up to 400 x 400 px | |
imageRGB = imread(imageURL); | |
% show source image | |
figure(); | |
imshow(imageRGB,[]); | |
set(gcf,'color','w'); | |
title('original image (RGB)'); | |
% convert to optical density (OD) space | |
imageOD = -log(double(imageRGB)+2); % add 2 to avoid artifacts of log transform | |
imagePixelsRGB = reshape(double(imageRGB),[],3)/255; | |
imagePixelsOD = reshape(imageOD,[],3); | |
% plot pixels in OD space | |
figure(); | |
scatter3(imagePixelsOD(:,1),imagePixelsOD(:,2),imagePixelsOD(:,3),10,imagePixelsRGB(:,:)); | |
title('Pixels in OD space shown in their RGB color'); | |
set(gcf,'color','w'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment