% Code by Phil Bedggood and Flora Hui % Questions to pabedg@unimelb.edu.au or huif@unimelb.edu.au % Citation: Hui F, et al (2014). "Quantitative spatial and temporal analysis of % fluorescein angiography dynamics in the eye". PLoS ONE xxx. % % Main input: A grayscale fluorescein angiogram TIFF stack (example "Sample.tif" included) % Main output: A registered version of this TIFF stack % Workflow: registerTiffStack -> PCAsmooth -> readTraceMask -> fitRegisteredTif clear; close all % ~~~~ Important settings to change ~~~~ cd('C:\Users\Phil\Documents\flora\Code for paper\Latest') makePCAImages = 1; % Use images generated from PCA filtering frameOn = 1; % Analyse from the first frame useVesselTraceData = 1; % 0 to not utilise the blood vessel masks % ~~~~ End important settings ~~~~ [theTifName,p] = uigetfile('*_reg.tif'); theTifInfo = imfinfo(theTifName); numFrames = length(theTifInfo); load([theTifName(1:end-8) '.mat'],'binFactor'); load([theTifName(1:end-8) '.mat'],'stackLength'); frameRate = numFrames/stackLength; ySize = theTifInfo(1).Height / binFactor; xSize = theTifInfo(1).Width / binFactor; % Time points all_x = linspace(0,stackLength,numFrames - frameOn + 1); % Loop each pixel in the intensity matrix and do the curve fit plotIndividual = 0; if useVesselTraceData numRuns = 4; else numRuns = 1; end colorVec = 'rbmg'; % Plot color for arteries, veins, all large vessels, all small vessels load([theTifName(1:end-8) '.mat'],'pixOfInterest') origPixOfInterest = pixOfInterest; % The ROI (intersection of a circle and a square that we selected earlier) for nn = 1:numRuns if makePCAImages load([theTifName(1:end-8) '_PCA.mat'],'intensityTraceMatrix'); else load([theTifName(1:end-8) '.mat'],'intensityTraceMatrix'); end if useVesselTraceData temp = zeros(ySize,xSize); temp(origPixOfInterest) = 1; switch nn case 1 load([theTifName(1:end-8) ' traced_artMask.mat']) pixOfInterest = find(arteryMask & temp); case 2 load([theTifName(1:end-8) ' traced_venMask.mat']) pixOfInterest = find(veinMask & temp); case 3 load([theTifName(1:end-8) ' traced_lrgMask.mat']) pixOfInterest = find(largeVesselMask & temp); case 4 load([theTifName(1:end-8) ' traced_capMask.mat']) smallVesselMask(end,:) = 0; pixOfInterest = find(smallVesselMask & temp); otherwise end pixOfInterest = intersect(pixOfInterest,origPixOfInterest); currentMask = false(ySize,xSize); currentMask(pixOfInterest) = 1; origPix_i = zeros(length(pixOfInterest),1); for pp = 1:length(pixOfInterest) origPix_i(pp) = find(pixOfInterest(pp) == origPixOfInterest); end else origPix_i = 1:length(origPixOfInterest); end coefficientStore = zeros(length(origPixOfInterest),3); % initialize an array to store measured parameters: time to half peak, slope at half peak, time to fall half way from peak, peak intensity and offset for pCount = 1:length(pixOfInterest) pp = origPix_i(pCount); fitThisPixel end riseTimeImage = NaN * ones(ySize,xSize); fallTimeImage = NaN * ones(ySize,xSize); offsetImage = NaN * ones(ySize,xSize); % Reshape the stored data into images riseTimeImage(pixOfInterest) = coefficientStore(origPix_i,1); fallTimeImage(pixOfInterest) = coefficientStore(origPix_i,2); offsetImage(pixOfInterest) = coefficientStore(origPix_i,3); plotIndividual = 1; plotPCA = 0; load([theTifName(1:end-8) '.mat'],'refImageNumber'); refImage = single(imread(theTifName,'tif',refImageNumber)); % Show the figures, adjusting the colormap label to factor in the scaling above figMaps = figure; hold on; subplot(3,1,1); imagesc(riseTimeImage); axis image; title('Half rise time (s)'); set(gca,'XTick',[]); set(gca,'YTick',[]); colorbar subplot(3,1,2); imagesc(fallTimeImage); axis image; title('Half fall time (s)');set(gca,'XTick',[]); set(gca,'YTick',[]); colorbar subplot(3,1,3); imagesc(offsetImage); axis image; title('Offset relative to peak');set(gca,'XTick',[]); set(gca,'YTick',[]); colorbar if numRuns > 1 plotIndividual = 0; end save([theTifName(1:end-8) '_fitted.mat'],'riseTimeImage') save([theTifName(1:end-8) '_fitted.mat'],'fallTimeImage','-append') save([theTifName(1:end-8) '_fitted.mat'],'offsetImage','-append') end