% Example for InvertIm
% Read 16-bit integer CT image of Rando phantom
im=dicomread('RandoPhantom.dcm');
fig=figure; colormap(gray)
% Show the original image
subplot(2,2,1)
imagesc(im)
axis image; axis off
% Plot the histogram for the original image
subplot(2,2,2)
[counts,x]=imhist(im,32768);
counts(counts<1)=0.7;
stairs(x,counts);
set(gca,'YScale','log')
axLim=axis;
axLim=[-2100 4200 0.7 1e4];
axis(axLim)
xlabel('Offset CT Number')
ylabel('Number of Pixels')
% Compute the inverted image
invIm=InvertIm(im,[],-2000,4096);
% Show the inverted image
subplot(2,2,3)
imagesc(invIm)
axis image; axis off
% Plot the histogram for the inverted image
subplot(2,2,4)
[counts,x]=imhist(invIm,32768);
counts(counts==0)=0.7;
stairs(x,counts);
set(gca,'YScale','log')
axis(axLim)
xlabel('Offset CT Number')
ylabel('Number of Pixels')