%% BODIPY Percent Positive Area Quantification %Author: Jordan Rolsma - University of California, Riverside %Features: %Calculates BODIPY (or other stain) percent positive area %Outputs figures with text including area (in px) and percent area %quantification %Housekeeping clearvars close all clc %Identifies image files in the working directory IM_FILE_all = dir(['*.png']); IM_FILE_all_new = struct2cell(IM_FILE_all); for file = [1:length(IM_FILE_all_new)] %Number of image files you want Matlab to read in the directory %File name BaseFileName = sprintf('%s', IM_FILE_all_new{1,file}(1:end-4)); %Read in each file I = imread(IM_FILE_all_new{1,file}); %Filtering se = strel('disk',5); %Morphological structuring element %Note: Higher numbers are more sensitive, values may vary depending on %your data set, but ensure that the number remains constant across the %entire analyzed data set. It is highly recommended to sample files %across your entire set to determine an appropriate element value %prior to analyzing your entire data set. I = imtophat(I,se); %Grayscale and binarization G = im2gray(I); BW = imbinarize(G); total{file} = bwarea(BW); %Calculate area of image imsize = size(I); imarea = imsize(:,1)*imsize(:,2); %Percentage calculation (two options) percent{file} = (total{1,file}./imarea)*100; %Note: this can be used %if total cell area is not available AND cells are ~100% confluent. %If cell area is available, it is highly recommended to check output %values against the line below to ensure consistency. %%%%or percent{file} = (total{1,file}./cellarea)*100; %This line is recommended %but requires you to have cell area (i.e., you used fixable BODIPY and %have fluorescence images defining cell borders or have cell %brightfield images with clearly defined cell borders). If you have %those images available, you can run those files through lines 12-46 to %obtain cell area. %Figure generation figure set(gcf,'units','inches','position',[1 1 2 2],'Color','w','PaperSize',[2 2],'PaperPosition',[0 0 2 2]) haxA = axes('units','inches','position',[0 0 2 2]); imagesc(BW) colormap(gray) set(gca,'visible','off'); axis equal; hold on text(0,100,['Area (px):' num2str(total{file})],'color','r','FontSize',12,'FontWeight','bold'); text(0,200,['Percent:' num2str(percent{file})],'color','r','FontSize',12,'FontWeight','bold'); hold off print(sprintf('%s_quant%d',BaseFileName),'-dpng'); end %Saves output values for all image files in the directory in a mat file save(sprintf('20231101_ASCMAHSs1T3_bodipy_AMPK_CC_5uM_14d_quant_data_final.mat')) %Convert mat to csv (optional, if desired) %Housekeeping clc clear vars close all load 20231101_ASCMAHSs1T3_bodipy_AMPK_CC_5uM_14d_quant_data_final.mat total = length(percent); for i = 1:total percent_bodipy{i} = (percent{i}); end percent_bodipy_array = cell2mat(percent_bodipy); avg_percent_bodipy = (sum(percent_bodipy_array))./length(percent_bodipy_array) %Saves data as a csv file writetable(cell2table([percent_bodipy avg_percent_bodipy]),'20231101_ASCMAHSs1T3_bodipy_AMPK_CC_5uM_14d_quant_data_final_percentbodipy.csv')