%This program extracts the data from the image stack clear; clc; dirname='E:\'; files=dir('*.tif'); fileIndex = find(~[files.isdir]); for k = 1:length(fileIndex); fname=files(fileIndex(k)).name; info = imfinfo(fname); num_images = numel(info); %reading the frames Frame= cell([num_images,1]); for i=1:num_images [X] = imread(fname,i, 'Info', info); Frame{i}=X; end %Making a sequence I = imread(fname,1, 'Info', info); % Preallocate the array sequence(:,:,1) = I; %Create image sequence array for p = 2:80 %% only the first 80 frames of the movie, this is enough to choose a frame which can give us the right contrast sequence(:,:,p) = imread(fname,p, 'Info', info); % Process sequence AdjSequence(:,:,p)=imadjust(sequence(:,:,p)); end %View results implay(AdjSequence(:,:,:)) pause(1); %select the frame you want to analyze FtoAnalyze=input('Select the frame you want to analyze:'); figure() imagen=Frame{FtoAnalyze}; SelCell=imadjust(imagen); imshow(SelCell); fileN=fname(1:end-4); a=[dirname '\' fileN]; title(a) xlabel('Select the cells you want to analyze') hold on; %%% ask how many cells are there in the image %%%for each of the cells, create a mask: cellTot= input('Enter the number of cells you want to select plus the local:'); for cellIndex=1:cellTot h=imellipse; EllPosition{cellIndex}= wait(h); BW = createMask(h); %figure, imshow(BW) %for each of the masks multiplies the mask for the sequence and %calculates the average intensity in each frame for i=1:num_images Objeto=immultiply(Frame{i},BW); %figure, imshow(Objeto) % find the mean intensity values of the selection objave(i)= mean2(Objeto);% this gives the mean intensity %of the whole image, now we have to normailze to the selected %region ind=find(Objeto); RegionPix=numel(ind); RegionFraction=RegionPix/numel(Objeto); AvgInt=objave./RegionFraction; end RAWInt{cellIndex}= AvgInt;% AvgInt;%RAW intensity end %creating the string to name the cells in the excel sheet myName{1}=['PrimaryLocal']; for i=2:cellTot myName{i}=['Cell_' num2str(i-1)]; end headers = [a, myName]; %creating the content of the file RAWMatrix=RAWInt{1}; for i=2:cellTot RAWMatrix=[RAWMatrix;RAWInt{i}]; end xlswrite('RAWData.xls', RAWMatrix',2*k); xlswrite('RAWData.xls', headers,(2*k)-1); % Writing the max indent frame p={'MaxIndentFrame';FtoAnalyze}; xlswrite('RAWData.xls', p,(2*k)-1,'A3') %%% saving the ellipse position Alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; for i=1:cellTot myName2{(2*i)-1}=['Ellipse_x' num2str(i)]; myName2{2*i}=['Ellipse_y' num2str(i)]; end headers2 = [myName2]; xlswrite('RAWData.xls', headers2,(2*k)-1,'A7'); %writing the ellipse positions in the excel file %label: EllPosition{1}; xlswrite('RAWData.xls', EllPosition,(2*k)-1,'A8'); for i=1:cellTot letter=[Alphabet((2*i)-1)]; myName3{i}=[letter num2str(8)]; xlswrite('RAWData.xls', EllPosition{i},(2*k)-1,myName3{i}); end %ploting the intensity profiles for each of the cells figure() plot(RAWInt{1},'r'); title(a) legend('Primary', 'Location', 'Best'); legendtext ='Primary Local'; hold all; for cellIndex=2:cellTot % Set the coloring code! %Graph colours: %So I make a string like this: colours='bgmckbgmck'; %And use the loop counter to select a colour character from the 'colours' string: %cellIndex plot(RAWInt{cellIndex},[colours(cellIndex)]); hold on; Cell{cellIndex}=['Cell_' num2str(cellIndex)]; hold all; end legend('Primary','Cell_1','Cell_2', 'Cell_3','Cell_4','Cell_5', 'Cell_6', 'Cell_7', 'Cell_8', 'Cell_9') plot(FtoAnalyze, RAWInt{1},'y.'); fileN=fname(1:end-4); SaveAllFigures(fileN,'emf') for i=1:cellTot Area{i}=area(EllPosition{i}(:,1), EllPosition{i}(:,2));%area Center{i}=mean(EllPosition{i}); %center letter4=[Alphabet(i+1)]; q={'Area';Area{i}; 'Center'; Center{i}(1);Center{i}(2) }; myName4{i}=[letter4 num2str(2)]; xlswrite('RAWData.xls', q,(2*k)-1,myName4{i}); end close(gcf); close(gcf); end