keyword stringclasses 7 values | repo_name stringlengths 8 98 | file_path stringlengths 4 244 | file_extension stringclasses 29 values | file_size int64 0 84.1M | line_count int64 0 1.6M | content stringlengths 1 84.1M ⌀ | language stringclasses 14 values |
|---|---|---|---|---|---|---|---|
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/main_disp_spline.m | .m | 818 | 31 | %Spline n = 3
t = -3:0.01:3;
x = t;
x = abs(x);
ind0 = (x >= 0 & x < 1);
ind1 = (x >= 1 & x < 2);
ind2 = (x >= 2);
x(ind0) = 2/3 - x(ind0).^2 + x(ind0).^3/2;
x(ind1) = (2 - x(ind1)).^3/6;
x(ind2) = 0;
figure,plot(t,x);hold on;
fprintf('Integral of Spline basis %1.2e\n',sum(x)*0.01);
x = t;
x = abs(x);
%F^{-1} of sinc^(3 + 1) (Wolfralmalpha)
x = 1/12*(abs(x - 2).^3 - 4*abs(x - 1).^3 + 3*(x - 2).*x.^2 + 4);
plot(t,x,'--');
fprintf('Integral of Spline basis %1.2e\n',sum(x)*0.01);
%% degree n = 4
x = -2.5:0.01:2.5;
x = 1/48*((x - 5/2).^4.*(-sign(x - 5/2)) + 5*(x - 3/2).^4.*sign(x - 3/2)...
- 10*(x - 1/2).^4.*sign(x - 1/2) + 10*(x + 1/2).^4.*sign(x + 1/2) ...
- 5*(x + 3/2).^4.*sign(x + 3/2) + (x + 5/2).^4.*sign(x + 5/2));
figure;
plot(x,'--');
fprintf('Integral of Spline basis %1.2e\n',sum(x)*0.01);
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/saveResults_old.m | .m | 10,248 | 203 | function saveResults_old(results, results_mol, results_graph,res_folder)
%SAVERESULTS_OLD Save all the results
%Save results in final file
fname = ['results____',...
results{1}.participant,'.csv'];
fileID = fopen(strcat(res_folder,filesep,...
results{1}.participant,filesep,fname),'w');
formatSpec = strcat('%s,%s,%s,%s,%s,%s,%s,',...%Wobble file
'%f,%f,%f,%i,%s,%s,',...%Name of Test file
'%i,%i,%i,%i,%i,%f,%f,',...%z max
'%f,%i,%i,%i,%f,%f,%f,',...%Recall
'%f,%f,%f,%f,%f,%f,%f,',...%MADz
'%f,%f,%f,%f,%f,%f,%f,%f,',...%FRCxy
'%f,%f,%f,%f,%f,%f,%f,%f,',...%RMSExyz_mol
'%f,%f,%f,%f,%f,%f,',...%Detection ratio_mol
'%f,%f,%f,',...%FWDM (RMSE)
'%f,%f,%f,%f,%f,%f,',...%Thres (RMSE)
'%f,%f,%f,',...%Z max Jaccard
'%f,%f,%f,',...%max Jaccard
'%f,%f,%f,',...%FWHM Jaccard
'%f,%f,','%f,%f,','%f,%f,',...%Z range FWHM Jaccard
'%f,','%f,','%f,',...%FWHM Jaccard Thres
'%f,%f,','%f,%f,','%f,%f,',...%Z range thres Jaccard
'%f,','%f,','%f,',...%Thres Jaccard
'%f,%f,%f,%f,%f,%f,%f,',...%Z max fitted precision
'%f,','%f,','%f,','%f','\n');%max fitted Jaccard
fprintf(fileID,strcat('Date Assessment,','Name of Software,','Dataset,','Density,',...
'Modality,','Wobble,','Wobble file,','TolXY,','TolZ,','Border,',...
'dim3D,','Name of GT File,','Name of Test file,',...
'# Fluorophores GT,','# Fluorophores Test,','# Error line,',...
'frame min,','frame max,','z min,','z max,','Thres Photon,',...
'TP,','FP,','FN,','Jaccard,','F-Score,','Recall,','Precision,',...
'RMSExyz,','RMSExy,','RMSEz,','MADxyz,','MADxy,','MADz,',...
'Dx,','Dy,','Dz,','Corr. photons,',...
'FSC,','FRCyz,','FRCxz,','FRCxy,',...
'SNRxyz,','SNRyz,','SNRxz,','SNRxy,',...
'TP_mol,','FN_mol,','Recall_mol,','RMSExyz_mol,','RMSExy_mol,','RMSEz_mol,',...
'MADxyz_mol,','MADxy_mol,','MADz_mol,','Detection ratio_mol,',...
'Z min RMSE,','min RMSE,','FWDM (RMSE),','min Z range FWDM (RMSE),','max Z range FWDM (RMSE),',...
'Range Thres (RMSE),','min Z range Thres (RMSE),','min Z range Thres (RMSE),','Thres (RMSE),',...
'Z max recall,','Z max precision,','Z max Jaccard,',...
'max recall,','max precision,','max Jaccard,',...
'FWHM recall,','FWHM precision,','FWHM Jaccard,',...
'min Z range FWHM recall,','max Z range FWHM recall,',...
'min Z range FWHM precision,','max Z range FWHM precision,',...
'min Z range FWHM Jaccard,','max Z range FWHM Jaccard,',...
'Range recall Thres,','Range precision Thres,','Range Jaccard Thres,',...
'min Z range thres recall,','max Z range thres recall,',...
'min Z range thres precision,','max Z range thres precision,',...
'min Z range thres Jaccard,','max Z range thres Jaccard,',...
'Thres recall,','Thres precision,','Thres Jaccard,',...
'Z min fitted RMSE,','min fitted RMSE,','FWDM (RMSE) fitted,',...
'min Z range FWDM (RMSE) fitted,','max Z range FWDM (RMSE) fitted,',...
'Z max fitted recall,','Z max fitted precision,','Z max fitted Jaccard,',...
'max fitted recall,','max fitted precision,','max fitted Jaccard','\n'));
if isempty(results_graph)
results_graph = fill_results_graph(results);
end
initLen = length(results_graph);
for k=1:length(results)
l=1;
notFound = true;
while l <= initLen && notFound
if strcmp(results_graph{l}.modality, results{k}.modality)...
&& strcmp(results_graph{l}.dataset, results{k}.dataset)...
&& strcmp(results_graph{l}.participant, results{k}.participant)...
&& strcmp(results_graph{l}.wobble, results{k}.wobble)...
&& results_graph{l}.photonT==results{k}.photonT...
&& ((strcmp(results_graph{l}.modality, '2D') && results{k}.dim3D==0)...
|| (~strcmp(results_graph{l}.modality, '2D') && results{k}.dim3D==1))
notFound = false;
else
l = l + 1;
if l > initLen && length(results_graph)==initLen
for fn = fieldnames(results_graph{l-1})'
results_graph{l}.(fn{1}) = results_graph{l-1}.(fn{1});
for m = 1:numel(results_graph{l}.(fn{1}))
try
results_graph{l}.(fn{1})(m) = nan;
end
end
end
end
end
end
if isempty(results{k}.wobble_file)
wobble_file = 'NaN';
else
wobble_file = results{k}.wobble_file;
end
fprintf(fileID,formatSpec,date,results{k}.test_fname,...
results{k}.dataset, results{k}.dataset(end-1:end), results{k}.modality,...
results{k}.wobble,wobble_file,...
results{k}.radTolXY,results{k}.radTolZ,...
results{k}.border,results{k}.dim3D,results{k}.gt_fname,...
results{k}.test_fname,results{k}.nloc_gt_initial,results{k}.nloc_test_initial,...
results{k}.Nerrorline,min(results{k}.loc(:,1)),max(results{k}.loc(:,1)),...
min(results{k}.loc(:,4)),max(results{k}.loc(:,4)),results{k}.photonT,...
results{k}.TP,results{k}.FP,results{k}.FN,...
results{k}.Jaccard,results{k}.Fscore,results{k}.recall,results{k}.precision,...
results{k}.RMSExyz,results{k}.RMSExy,results{k}.RMSEz,...
results{k}.MADxyz,results{k}.MADxy,results{k}.MADz,results{k}.distX,...
results{k}.distY,results{k}.distZ,results{k}.corrPhoton,...
results{k}.FSC,results{k}.FRC{1},results{k}.FRC{2},results{k}.FRC{3},...
results{k}.SNR{1},results{k}.SNR{2},...
results{k}.SNR{3},results{k}.SNR{4},...
results_mol{k}.TPmol,results_mol{k}.FNmol,...
results_mol{k}.recall_mol,...
results_mol{k}.RMSExyz_mol,results_mol{k}.RMSExy_mol,results_mol{k}.RMSEz_mol,...
results_mol{k}.MADxyz_mol,results_mol{k}.MADxy_mol,results_mol{k}.MADz_mol,...
results_mol{k}.ratio_det_per_mol_ave,...
results_graph{l}.z_min_RMSE,results_graph{l}.min_RMSE,results_graph{l}.FWDM,...
results_graph{l}.z_range_FWDM(1),results_graph{l}.z_range_FWDM(2),...
results_graph{l}.FWDM_T, results_graph{l}.z_range_T_RMSE(1),...
results_graph{l}.z_range_T_RMSE(2),results_graph{l}.RMSE_thres,...
results_graph{l}.z_max_metric(1),results_graph{l}.z_max_metric(2),results_graph{l}.z_max_metric(3),...
results_graph{l}.max_metric(1),results_graph{l}.max_metric(2),results_graph{l}.max_metric(3),...
results_graph{l}.FWHM(1),results_graph{l}.FWHM(2),results_graph{l}.FWHM(3),...
results_graph{l}.z_range_FWHM(1,1),results_graph{l}.z_range_FWHM(1,2),...
results_graph{l}.z_range_FWHM(2,1),results_graph{l}.z_range_FWHM(2,2),...
results_graph{l}.z_range_FWHM(3,1),results_graph{l}.z_range_FWHM(3,2),...
results_graph{l}.FWHM_T(1),results_graph{l}.FWHM_T(2),results_graph{l}.FWHM_T(3),...
results_graph{l}.z_range_T_metric(1,1),results_graph{l}.z_range_T_metric(1,2),...
results_graph{l}.z_range_T_metric(2,1),results_graph{l}.z_range_T_metric(2,2),...
results_graph{l}.z_range_T_metric(3,1),results_graph{l}.z_range_T_metric(3,2),...
results_graph{l}.metric_thres(1),results_graph{l}.metric_thres(2),results_graph{l}.metric_thres(3),...
results_graph{l}.z_min_fitted,results_graph{l}.min_fitted,...
results_graph{l}.FWDM_fitted,results_graph{l}.z_range_FWDM_fitted(1),results_graph{l}.z_range_FWDM_fitted(2),...
results_graph{l}.z_max_fitted(1), results_graph{l}.z_max_fitted(2),results_graph{l}.z_max_fitted(3),...
results_graph{l}.max_fitted(1), results_graph{l}.max_fitted(2),results_graph{l}.max_fitted(3));
end
fclose(fileID);
fprintf('The assessment results are saved in the file %s\n',fname);
end
function results_graph = fill_results_graph(results)
res_len = length(results);
results_graph = cell(res_len,1);
for l = 1:res_len
results_graph{l}.dim3D = results{l}.dim3D;
results_graph{l}.photonT = results{l}.photonT;
results_graph{l}.wobble = results{l}.wobble;
results_graph{l}.participant = results{l}.participant;
results_graph{l}.dataset = results{l}.dataset;
results_graph{l}.modality = results{l}.modality;
results_graph{l}.z_min_RMSE = nan;
results_graph{l}.min_RMSE = nan;
results_graph{l}.FWDM = nan;
results_graph{l}.z_range_FWDM(1) = nan;
results_graph{l}.z_range_FWDM(2) = nan;
results_graph{l}.FWDM_T = nan;
results_graph{l}.z_range_T_RMSE(1) = nan;
results_graph{l}.z_range_T_RMSE(2) = nan;
results_graph{l}.RMSE_thres = nan;
results_graph{l}.z_max_metric(1) = nan;
results_graph{l}.z_max_metric(2) = nan;
results_graph{l}.z_max_metric(3) = nan;
results_graph{l}.max_metric(1) = nan;
results_graph{l}.max_metric(2) = nan;
results_graph{l}.max_metric(3) = nan;
results_graph{l}.FWHM(1) = nan;
results_graph{l}.FWHM(2) = nan;
results_graph{l}.FWHM(3) = nan;
results_graph{l}.z_range_FWHM(1,1) = nan;
results_graph{l}.z_range_FWHM(1,2) = nan;
results_graph{l}.z_range_FWHM(2,1) = nan;
results_graph{l}.z_range_FWHM(2,2) = nan;
results_graph{l}.z_range_FWHM(3,1) = nan;
results_graph{l}.z_range_FWHM(3,2) = nan;
results_graph{l}.FWHM_T(1) = nan;
results_graph{l}.FWHM_T(2) = nan;
results_graph{l}.FWHM_T(3) = nan;
results_graph{l}.z_range_T_metric(1,1) = nan;
results_graph{l}.z_range_T_metric(1,2) = nan;
results_graph{l}.z_range_T_metric(2,1) = nan;
results_graph{l}.z_range_T_metric(2,2) = nan;
results_graph{l}.z_range_T_metric(3,1) = nan;
results_graph{l}.z_range_T_metric(3,2) = nan;
results_graph{l}.metric_thres(1) = nan;
results_graph{l}.metric_thres(2) = nan;
results_graph{l}.metric_thres(3) = nan;
results_graph{l}.z_min_fitted = nan;
results_graph{l}.min_fitted = nan;
results_graph{l}.FWDM_fitted = nan;
results_graph{l}.z_range_FWDM_fitted(1) = nan;
results_graph{l}.z_range_FWDM_fitted(2) = nan;
results_graph{l}.z_max_fitted(1) = nan;
results_graph{l}.z_max_fitted(2) = nan;
results_graph{l}.z_max_fitted(3) = nan;
results_graph{l}.max_fitted(1) = nan;
results_graph{l}.max_fitted(2) = nan;
results_graph{l}.max_fitted(3) = nan;
end
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/im_metrics.m | .m | 4,365 | 134 | function [Iref,Iest,varargout] = im_metrics(posEst,posRef,sig,pix_size,im_size,winLen,areaCenter,doFSC,varargin)
%im_metrics Provides image based metrics : SNR, FRC
% image obtained by convolving the positions with a gaussian (sigma sig)
% SNR = 10*log_10(norm(posRef_gauss,2)^2/norm(posRef_gauss-posEst_gauss,2)^2)
% posEst : estimated positions
% posRef : reference positions
% sig : sigma of the gaussian. e.g. Sage's sig ten times lower than the PSF
% im_size : size of the obtained image
renderOnly = false;doCorr = true;
k=1;
while k< nargin - 8
switch varargin{k}
case 'renderOnly'
renderOnly = varargin{k+1};
case 'doCorr'
doCorr = varargin{k+1};
end
k=k+2;
end
Iref3D = gauss_render(posRef, sig, pix_size, im_size,doCorr);
Iest3D = gauss_render(posEst, sig, pix_size, im_size,doCorr);
Iref = cell(4,1); Iest = cell(4,1); SNR = cell(4,1); FRC = cell(3,1);
Iref{1} = Iref3D; Iest{1} = Iest3D;
for k=1:3
Iref{1+k} = squeeze(sum(Iref3D, k));
Iest{1+k} = squeeze(sum(Iest3D, k));
end
if ~renderOnly
for k=1:4
SNR{k} = 10*log10(sum(Iref{k}(:).^2)/sum((Iref{k}(:) - Iest{k}(:)).^2));
end
%2D: FRC
%FRC = FRCtrueLoc(posEst(:,1:2), posRef(:,1:2), im_size(1:2), 1/pix_size, pix_size, true);%histogram
%FRC = imres_ims(Iest{4}, Iref{4}, pix_size, false);%gauss
%new file, same result for 2D
if sum(Iest{1}(:))==0
FRC = nan(3,1);
FRC = mat2cell(FRC,ones(3,1));
else
for k=1:3
FRC{k} = frc_mod(Iest{k+1}, Iref{k+1});
FRC{k} = frctoresolution(FRC{k}, im_size(1))*pix_size;
end
end
%3D: FSC
if doFSC && sum(Iest{1}(:))~=0
winLen = min(winLen/pix_size,im_size(1));%window length
centerROI = areaCenter/pix_size;%center
if centerROI(1) + winLen/2 > im_size(1) || centerROI(1) - winLen/2 < 0 ...
|| centerROI(2) + winLen/2 > im_size(2) || centerROI(2) - winLen/2 < 0
warning('ROI in FSC out of boundary');
return
end
areaROI{1} = 1 - winLen/2+centerROI(1):centerROI(1) + winLen/2;
areaROI{2} = 1 - winLen/2+centerROI(2):centerROI(2) + winLen/2;
timer_fsc = tic;
FSC = frc_mod(Iest{1}(areaROI{1},areaROI{2},:), Iref{1}(areaROI{1},areaROI{2},:));
FSC = frctoresolution3D(FSC, winLen)*pix_size;
%FSC = frctoresolution(FSC, im_size(1))*pix_size;%zero-padded,not working for 3D
fprintf('FSC calculation...%1.2f s\n',toc(timer_fsc))
else
FSC = nan;
end
varargout{1} = SNR;
varargout{2} = FRC;
varargout{3} = FSC;
end
end
function resolution = frctoresolution3D(frc_in, sz)
% Check that the curvefit toolbox function smooth exists
TB_curve=0;
try
TB_d=toolboxdir('curvefit');
TB_curve=1;
catch
warning('Curvefit toolbox not available. Using another not optimal smoothing method for FRC.')
end
% Smoot the FRC curve
% Least squares interpolation for curve smoothing
sspan = ceil(sz/20); % Smoothing span
if (sz/20)<5
sspan = 5;
end
sspan = sspan + (1-mod(sspan,2));
if TB_curve
p = pwd; % hack to avoid the function shadwoing by smooth from dip_image
cd([TB_d filesep 'curvefit'])
frc_in = double(smooth(frc_in,sspan,'loess'));
cd(p)
else
frc_in = double(gaussf(frc_in,.9))';
end
q = (0:(length(frc_in)-1))'/sz; % Spatial frequencies
% Calculate intersections between the FRC curve and the threshold curve
% isects = polyxpoly(q,frc_in,q,thresholdcurve);
thresholdcurve = 1/7*ones(size(frc_in));%can use other threshold
isects = isect(q,frc_in,thresholdcurve);
% Find first intersection to obtain the resolution
% Throw away intersections at frequencies beyond the Nyquist frequency
isects = isects(isects<0.5);
if isempty(isects)
resolution = 1/0.5;%set the "best" resolution reachable
else
% Find the first intersection where the FRC curve is decreasing
isect_inds = 1+floor(sz*isects); % Indices of the intersections
for ii = 1:length(isect_inds)
isect_ind = isect_inds(ii);
if frc_in(isect_ind+1) < frc_in(isect_ind)
resolution = 1/isects(ii);
break
end
end
end
if ~exist('resolution','var')
resolution = nan;
fprintf(' -- Could not find the resolution --\n')
end
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/assessment_mol.m | .m | 2,642 | 73 | function perf_metrics = assessment_mol(fpath, result_fname)
%ASSESSMENT_MOL : produces some metrics based on molecule
% -Averaged position among paired ones
% -TP as long as one there is one pairing
% Written by Thanh-an Pham, 2016
try
pairings = csvread([fpath, filesep, result_fname]);
catch
warning('No pairings at all !\n');
perf_metrics = setMetrics(0,nan,0,0,0,0,0, 0,0);
return;
end
%FP = result.FP;
nFeat = str2double(result_fname(strfind(result_fname,'____nFeat_')+10:strfind(result_fname,'.csv')-1));
[~, ind_order] = sort(pairings(:,1));
pairings_sorted = pairings(ind_order,:);
%diff on [x,y,z], hoping no round-error => worst case : apply round(...)
Nmol = diff(find([1;diff(pairings_sorted(:,2))]...
| [1;diff(pairings_sorted(:,3))]...
| [1;diff(pairings_sorted(:,4))]));
TP = 0;
FN = 0;
RMSExy = zeros(length(Nmol),1);
RMSExyz = RMSExy; RMSEz = RMSExy;
MADxy = RMSExy; MADz = MADxy; MADxyz = MADxy;
ratio_det_per_mol = RMSExy;
for m = 1:length(Nmol)
curr_ind = 1 + sum(Nmol(1:m-1));
paired_mol = pairings_sorted(curr_ind:curr_ind + Nmol(m)-1,1+end - nFeat:end);
gt_pos = pairings_sorted(curr_ind,1:end-nFeat);%same position
if all(isnan(paired_mol(:)))
FN = FN + 1;
else
TP = TP + 1;
Ndetection = sum(~isnan(paired_mol(:,1)));
avePos = sum(paired_mol(:,2:4),1,'omitnan')/Ndetection;
RMSExyz(m) = norm(avePos - gt_pos(2:4),2)^2;
RMSExy(m) = sum((avePos(1:2) - gt_pos(2:3)).^2);
RMSEz(m) = (avePos(end) - gt_pos(4))^2;
MADxyz(m) = sum(abs(avePos - gt_pos(2:4)));
MADxy(m) = sum(abs(avePos(1:2) - gt_pos(2:3)));
MADz(m) = abs(avePos(3) - gt_pos(4));
ratio_det_per_mol(m) = Ndetection/Nmol(m);
end
end
perf_metrics = setMetrics(TP,FN,RMSExy,RMSEz,RMSExyz,...
MADxy, MADz, MADxyz,ratio_det_per_mol);
end
function perf_metrics = setMetrics(TP,FN,RMSExy,RMSEz,RMSExyz,...
MADxy, MADz, MADxyz,ratio_det_per_mol)
perf_metrics.TPmol = TP;
perf_metrics.FNmol = FN;
perf_metrics.RMSExy_mol = sqrt(sum(RMSExy)/TP);
perf_metrics.RMSEz_mol = sqrt(sum(RMSEz)/TP);
perf_metrics.RMSExyz_mol = sqrt(sum(RMSExyz)/TP);
perf_metrics.MADxy_mol = sum(MADxy)/TP;
perf_metrics.MADz_mol = sum(MADz)/TP;
perf_metrics.MADxyz_mol = sum(MADxyz)/TP;
%perf_metrics.Jaccard_mol = TP/(FN + FP + TP);
perf_metrics.recall_mol = TP/(TP + FN);
%perf_metrics.precision_mol = TP/(TP + FP);
%perf_metrics.Fscore_mol = 2*perf_metrics.precision_mol*perf_metrics.rate_detection_mol...
% /(perf_metrics.precision_mol + perf_metrics.recall_mol);
perf_metrics.ratio_det_per_mol_ave = sum(ratio_det_per_mol)/TP;
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/assessment_main_automatic.m | .m | 9,678 | 223 | %% ASSESSMENT PROGRAM (MAIN) FOR AUTOMATIC RUN
% ASSESSMENT SCRIPT written by Thanh-an Pham (EPFL): 12-Jul-2016
% Expect standardized input files in folder 'participant_name/standard'
% converted by participant-specific converter script "convert_(participant_name).m"
%% Initialisation for for boucle
clear
res_fold = 'assessment_results';
participants = dir(pwd);
ind2rm = false(length(participants),1);
for k=1:length(participants)
ind2rm(k) = ~participants(k).isdir...
|| ~exist(fullfile(participants(k).name,'standard'),'dir')...
|| exist(fullfile(res_fold,participants(k).name),'dir')...
...%below select the ones to assess
|| ~(strcmpi(participants(k).name,'BaselineLocalization')...
|| strcmpi(participants(k).name,'GT')...
|| strcmpi(participants(k).name,'SMAP')...
|| strcmpi(participants(k).name,'CEL0')...
|| strcmpi(participants(k).name,'CSpline')...
|| strcmpi(participants(k).name,'RANDOM')...
|| strcmpi(participants(k).name,'STORMChaser')...
|| strcmpi(participants(k).name,'MIATool-RMS')...
|| strcmpi(participants(k).name,'MIATool-JAC')...
|| strcmpi(participants(k).name,'MIATool')...
|| strcmpi(participants(k).name,'EasyDHPSF')...
|| strcmpi(participants(k).name,'mlePALM')...
|| strcmpi(participants(k).name,'Phasor-ThunderSTORM')...
|| strcmpi(participants(k).name,'SOLAR_STORM')...
|| strcmpi(participants(k).name,'QC-STORM')...
|| strcmpi(participants(k).name,'NeuralSTORM')...
|| strcmpi(participants(k).name,'3D-WTM'));
end
participants(ind2rm) = [];
mat_dir = 'mat_files';%folder to save mat files
mkdir(mat_dir);
intensity = [0,0.25];%photon counts below to exclude (e.g. 0.1 => 90% are kept)
maxCounter = 1;%choose a divider of nSettings*length(fnames) (e.g. multiple of 2) for tmp save
%%
%parpool(2);
fprintf('Did you initialise DIP library ?\n');
Tol = 250;%25:25:400;
tic
%parfor kk = 1:length(Tol)
for ll = 1:length(participants)
% Parameters
param_input = [];
param_input.fov = [6400, 6400, 1500];%nm, Field Of View
param_input.radTol = [250,500];%nm, (XY and Z)
param_input.pix_siz = 10;%nm, pixel size for rendering
param_input.FWHM = 20;%nm, rendering with Gaussian convolution (FWHM)
param_input.winLen = 5120;%nm, window length XY for FSC
param_input.areaCenter = [3200,3200];%nm, area center for window in FSC
param_input.exclusion = 450;%nm, border exclusion
param_input.opix_siz = 2;%nm, orthoview zoomed pixel size
param_input.oPos = [1920,1920,-750];%(X,Y,Z) = (top, left, bottom),nm for MT
param_input.ofov = [1280,1280,1500];%nm
param_input.result_folder = res_fold;
param_input.thresRMSE = 62.5;%250/4
param_input.thresMetrics = [0.25,0.5;0.25,0.5;25,50];%[0.5,0.5,0.5];
param_input.Nsamples_smooth = 5;
param_input.Alpha_smooth = 2;
param_input.participant = participants(ll).name;
if strcmp(param_input.participant,'RANDOM')
param_input.doFSC = false;%do FSC or not
param_input.saveFig = false;%save Orthoview (& 3D) or not
else
param_input.doFSC = true;%do FSC or not
param_input.saveFig = true;%save Orthoview (& 3D) or not
end
% Settings
fnames = dir(fullfile(param_input.participant,'standard','MT*'));
fnames = [fnames;dir(fullfile(param_input.participant,'standard','ER*'))];
param_input.wobble_files = dir(fullfile(param_input.participant,'upload','Wobble*'));
param_input.beads_files = dir(fullfile(param_input.participant,'standard','Beads*'));
fileID = fopen(fullfile(param_input.participant,'upload','wobble.txt'),'r');
wobble = unique([~strcmp(fscanf(fileID,'%s'),'no'),false]);
nSettings = length(intensity)*length(wobble);
fprintf('%s : %i dataset(s), %i setting(s) per dataset => %i run(s)\n',...
param_input.participant, length(fnames),nSettings,nSettings*length(fnames));
lenPart = nSettings*length(fnames)/maxCounter;
% Assessment for one participant's files ---Frame & Molecule based---
param_input.firstTime = true;%for folder existence verification
results = cell(lenPart,1);
results_mol = results;
overalltimer = tic;
l = 1;counter = 1;
for int_iter = 1:length(intensity)
for wobble_iter = 1:length(wobble)
for k = 1:length(fnames)
dataset_timer = tic;
param_input.int_thres = intensity(int_iter);
sep = strfind(fnames(k).name,'____');
param_input.dim3D = ~strcmp(fnames(k).name(sep(1)+4:sep(2)-1),'2D');
param_input.wobble = wobble(wobble_iter);
param_input.test_name = fnames(k).name;
results{l} = assessment_frame(param_input);
%only requires name
results_mol{l} = assessment_mol(results{l}.res_path,...
results{l}.fname_pairings);
fprintf('Time for dataset/settings %i : %1.3f s\n',(counter-1)*lenPart + l,toc(dataset_timer));
param_input.firstTime = false;
l = l + 1;
if l > lenPart && maxCounter > 1 %memory trouble ? One mat file > 700mb
tmp_struct = [];
tmp_struct.results = results;
tmp_struct.results_mol = results_mol;
save_in_parfor(fullfile(mat_dir,sprintf('%s____results_part_%i', param_input.participant,counter)), tmp_struct);
l = 1;
counter = counter + 1;
end
end
end
end
fprintf('Assessment done for %s in %f\n',param_input.participant,toc(overalltimer))
% Regroup in one variable
%
if maxCounter > 1
results = cell(nSettings*length(fnames),1);
results_mol = results;
for k = 1:maxCounter
tmp = load(fullfile(mat_dir,sprintf('%s____results_part_%i.mat',param_input.participant,k)));
results(1+(k-1)*lenPart:k*lenPart) = tmp.results;
results_mol(1+(k-1)*lenPart:k*lenPart) = tmp.results_mol;
end
tmp = [];
fprintf('Results loaded and regrouped for %s\n',param_input.participant);
end
% Figures production
%rmpath(fullfile(param_input.result_folder,param_input.participant));
addpath(fullfile(param_input.result_folder,param_input.participant));
filesOI = dir(fullfile(param_input.result_folder,param_input.participant,'pairings*'));
Nfiles = length(filesOI);
modalSet = [];dataSet = [];wobSet = [];
intSet = cell(2,1); intSet{1} = 0;
for ii = 1:Nfiles
sep = strfind(filesOI(ii).name,'____');
strDataset = filesOI(ii).name(sep(1)+4:sep(2)-1);
if isempty(find(strcmp(strDataset,dataSet),1))
dataSet{end+1} = strDataset;
end
strMod = filesOI(ii).name(sep(2)+4:sep(3)-1);
if isempty(find(strcmp(strMod,modalSet),1))
modalSet{end+1} = strMod;
end
strInt = str2double(filesOI(ii).name(strfind(filesOI(ii).name,'photonT_')+8:sep(7)-1));
if ~ismember(strInt,intSet{2}) && strInt~=0
intSet{2} = [intSet{2}, strInt];
end
strWob = filesOI(ii).name(strfind(filesOI(ii).name,'wobble_')+7:sep(5)-1);
if isempty(find(strcmp(strWob,wobSet),1))
wobSet{end+1} = strWob;
end
end
if isempty(intSet{2})
intSet(2) = [];
end
%only wobble on/off is shown on same graph
NelPerFig = numel(wobSet);
if mod(NelPerFig,1)~=0
error('Number of files in results incorrect');
end
input = cell(NelPerFig,1);
m = 1;
results_graph = cell(length(dataSet)*length(modalSet)*length(intSet),1);
for ii = 1:length(dataSet)
for jj = 1:length(modalSet)
for k = 1:length(intSet)
ind_count = 1;
for l = 1:Nfiles
fname = filesOI(l).name;
dim3Dread = str2double(fname(strfind(fname,'____dim3D_')...
+10));
photon_t = str2double(fname(strfind(fname,'____photonT_')...
+12:strfind(fname,'____date')-1));
if ismember(photon_t, intSet{k})...
&& any(strfind(fname, dataSet{ii}))...
&& any(strfind(fname, strcat('____',modalSet{jj},'____')))...
&& ((strcmp(modalSet{jj},'2D') && dim3Dread==0)...
|| (~strcmp(modalSet{jj},'2D') && dim3Dread==1))
input{ind_count} = fname;
ind_count = ind_count + 1;
end
end
if ~all(cellfun(@isempty, input))
results_graph{m} = assessment_graph(input, 'fov', param_input.fov,...
'metrics', param_input.thresMetrics,...
'Nsamples_smooth',param_input.Nsamples_smooth,...
'Alpha_smooth',param_input.Alpha_smooth,...
'fold_path',param_input.result_folder);%[recall; precision; jaccard]
m = m + 1;
input = cell(NelPerFig,1);
end
end
end
end
results_graph = cat(1,results_graph{:});
fprintf('Figures saved and additional metrics calculated\n');
% Save the results file (private and public)
saveResults(results, results_mol, results_graph, param_input.result_folder);
savePublic(results, results_mol, results_graph, param_input.result_folder);
fprintf('Results saved\n');
end
%end
toc | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/saveastiff.m | .m | 12,013 | 303 | function res = saveastiff(data, path, options)
% options.color
% : true or FALSE
% : If this is true, third dimension should be 3 and the data is saved as a color image.
% options.compress
% : 'no', 'lzw', 'jpeg' or 'adobe'.
% Compression type.
% 'no' : Uncompressed(Default)
% 'lzw' : lossless LZW
% 'jpeg' : lossy JPEG (When using JPEG compression, ImageWidth,
% ImageLength, and RowsPerStrip must be multiples of 16.)
% 'adobe' : lossless Adobe-style
% options.message
% : TRUE or false.
% If this is false, all messages are skipped.
% options.append
% : true or FALSE
% If path is exist, the data is appended to an existing file.
% If path is not exist, this options is ignored.
% options.overwrite
% : true or FALSE
% Overwrite to an existing file.
% options.big
% : true or FALSE,
% Use 64 bit addressing and allows for files > 4GB
%
% Defalut value of 'options' is
% options.color = false;
% options.compress = 'no';
% options.message = true;
% options.append = false;
% options.overwrite = false;
% options.big = false;
%
% res : Return value. It is 0 when the function is finished with no error.
% If an error is occured in the function, it will have a positive
% number (error code).
%
% Copyright (c) 2012, YoonOh Tak
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
% * Neither the name of the Gwangju Institute of Science and Technology (GIST), Republic of Korea nor the names
% of its contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
tStart = tic;
errcode = 0;
try
%% Init options parameter
if nargin < 3 % Use default options
options.color = false;
options.compress = 'no';
options.message = true;
options.append = false;
options.overwrite = false;
end
if ~isfield(options, 'message'), options.message = true; end
if ~isfield(options, 'append'), options.append = false; end
if ~isfield(options, 'compress'), options.compress = 'no'; end
if ~isfield(options, 'color'), options.color = false; end
if ~isfield(options, 'overwrite'), options.overwrite = false; end
if isfield(options, 'big') == 0, options.big = false; end
if isempty(data), errcode = 1; assert(false); end
if (options.color == false && ndims(data) > 3) || ...
(options.color == true && ndims(data) > 4)
% Maximum dimension of a grayscale image is 3 of [height, width, frame]
% Maximum dimension of a color image is 4 of [height, width, color, frame]
errcode = 2; assert(false);
end
%% Get image informations
% http://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.html
if ~options.color
if ndims(data) >= 4, errcode = 2; assert(false); end;
[height, width, depth] = size(data);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.Photometric = Tiff.Photometric.MinIsWhite;
% tagstruct.Photometric = Tiff.Photometric.Mask;
% tagstruct.Photometric = Tiff.Photometric.Separated;
else
if ndims(data) >= 5, errcode = 2; assert(false); end;
[height, width, cc, depth] = size(data); % cc: color channels. 3: rgb, 4: rgb with alpha channel
if cc ~= 3 && cc ~= 4, errcode = 3; assert(false); end;
tagstruct.Photometric = Tiff.Photometric.RGB;
% tagstruct.Photometric = Tiff.Photometric.CIELab;
% tagstruct.Photometric = Tiff.Photometric.ICCLab;
% tagstruct.Photometric = Tiff.Photometric.ITULab;
% (Unsupported)tagstruct.Photometric = Tiff.Photometric.Palette;
% (Unsupported)tagstruct.Photometric = Tiff.Photometric.YCbCr;
end
tagstruct.ImageLength = height;
tagstruct.ImageWidth = width;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky; % (RGB RGB,RGB RGB,RGB RGB), http://www.awaresystems.be/imaging/tiff/tifftags/planarconfiguration.html
% (Unsupported)tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Separate; % (RRR RRR, GGG GGG, BBB BBB), % http://www.awaresystems.be/imaging/tiff/tifftags/planarconfiguration.html
%% Complex number
% http://www.awaresystems.be/imaging/tiff/tifftags/samplesperpixel.html
if ~options.color && isreal(data) % Grayscale image with real numbers
tagstruct.SamplesPerPixel = 1;
data = reshape(data, height, width, 1, depth);
elseif ~options.color && ~isreal(data) % Grayscale image with complex numbers
tagstruct.SamplesPerPixel = 2;
data = reshape([real(data) imag(data)], height, width, 2, depth);
elseif options.color && isreal(data) % Color image with real numbers
tagstruct.SamplesPerPixel = cc;
if cc == 4
tagstruct.ExtraSamples = Tiff.ExtraSamples.AssociatedAlpha; % The forth channel is alpha channel
end
data = reshape(data, height, width, cc, depth);
elseif options.color && ~isreal(data) % Color image with complex numbers
tagstruct.SamplesPerPixel = cc * 2;
if cc == 3
tagstruct.ExtraSamples = repmat(Tiff.ExtraSamples.Unspecified, 1, 3); % 3(real)+3(imag) = 6 = 3(rgb) + 3(Extra)
else
tagstruct.ExtraSamples = repmat(Tiff.ExtraSamples.Unspecified, 1, 5); % 4(real)+4(imag) = 8 = 3(rgb) + 5(Extra)
end
data = reshape([real(data) imag(data)], height, width, cc*2, depth);
end
%% Image compression
% http://www.awaresystems.be/imaging/tiff/tifftags/compression.html
switch lower(options.compress)
case 'no'
tagstruct.Compression = Tiff.Compression.None;
case 'lzw'
tagstruct.Compression = Tiff.Compression.LZW;
case 'jpeg'
tagstruct.Compression = Tiff.Compression.JPEG;
case 'adobe'
tagstruct.Compression = Tiff.Compression.AdobeDeflate;
otherwise
% Use tag nubmer in http://www.awaresystems.be/imaging/tiff/tifftags/compression.html
tagstruct.Compression = options.compress;
end
%% Sample format
% http://www.awaresystems.be/imaging/tiff/tifftags/sampleformat.html
switch class(data)
% Unsupported Matlab data type: char, logical, cell, struct, function_handle, class.
case {'uint8', 'uint16', 'uint32'}
tagstruct.SampleFormat = Tiff.SampleFormat.UInt;
case {'int8', 'int16', 'int32'}
tagstruct.SampleFormat = Tiff.SampleFormat.Int;
if options.color
errcode = 4; assert(false);
end
case {'single', 'double', 'uint64', 'int64'}
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
otherwise
% (Unsupported)Void, ComplexInt, ComplexIEEEFP
errcode = 5; assert(false);
end
%% Bits per sample
% http://www.awaresystems.be/imaging/tiff/tifftags/bitspersample.html
switch class(data)
case {'uint8', 'int8'}
tagstruct.BitsPerSample = 8;
case {'uint16', 'int16'}
tagstruct.BitsPerSample = 16;
case {'uint32', 'int32'}
tagstruct.BitsPerSample = 32;
case {'single'}
tagstruct.BitsPerSample = 32;
case {'double', 'uint64', 'int64'}
tagstruct.BitsPerSample = 64;
otherwise
errcode = 5; assert(false);
end
%% Rows per strip
maxstripsize = 8*1024;
tagstruct.RowsPerStrip = ceil(maxstripsize/(width*(tagstruct.BitsPerSample/8)*size(data,3))); % http://www.awaresystems.be/imaging/tiff/tifftags/rowsperstrip.html
if tagstruct.Compression == Tiff.Compression.JPEG
tagstruct.RowsPerStrip = max(16,round(tagstruct.RowsPerStrip/16)*16);
end
%% Overwrite check
if exist(path, 'file') && ~options.append
if ~options.overwrite
errcode = 6; assert(false);
end
end
%% Save path configuration
path_parent = pwd;
[pathstr, fname, fext] = fileparts(path);
if ~isempty(pathstr)
if ~exist(pathstr, 'dir')
mkdir(pathstr);
end
cd(pathstr);
end
%% Write image data to a file
file_opening_error_count = 0;
while ~exist('tfile', 'var')
try
if ~options.append % Make a new file
s=whos('data');
if s.bytes > 2^32-1 || options.big
tfile = Tiff([fname, fext], 'w8'); % Big Tiff file
else
tfile = Tiff([fname, fext], 'w');
end
else
if ~exist([fname, fext], 'file') % Make a new file
s=whos('data');
if s.bytes > 2^32-1 || options.big
tfile = Tiff([fname, fext], 'w8'); % Big Tiff file
else
tfile = Tiff([fname, fext], 'w');
end
else % Append to an existing file
tfile = Tiff([fname, fext], 'r+');
while ~tfile.lastDirectory(); % Append a new image to the last directory of an exiting file
tfile.nextDirectory();
end
tfile.writeDirectory();
end
end
catch
file_opening_error_count = file_opening_error_count + 1;
pause(0.1);
if file_opening_error_count > 5 % automatically retry to open for 5 times.
reply = input('Failed to open the file. Do you wish to retry? Y/n: ', 's');
if isempty(reply) || any(upper(reply) == 'Y')
file_opening_error_count = 0;
else
errcode = 7;
assert(false);
end
end
end
end
for d = 1:depth
tfile.setTag(tagstruct);
tfile.write(data(:, :, :, d));
if d ~= depth
tfile.writeDirectory();
end
end
tfile.close();
if exist('path_parent', 'var'), cd(path_parent); end
tElapsed = toc(tStart);
if options.message
display(sprintf('The file was saved successfully. Elapsed time : %.3f s.', tElapsed));
end
catch exception
%% Exception management
if exist('tfile', 'var'), tfile.close(); end
switch errcode
case 1
if options.message, error '''data'' is empty.'; end;
case 2
if options.message, error 'Data dimension is too large.'; end;
case 3
if options.message, error 'Third dimesion (color depth) should be 3 or 4.'; end;
case 4
if options.message, error 'Color image cannot have int8, int16 or int32 format.'; end;
case 5
if options.message, error 'Unsupported Matlab data type. (char, logical, cell, struct, function_handle, class)'; end;
case 6
if options.message, error 'File already exists.'; end;
case 7
if options.message, error(['Failed to open the file ''' path '''.']); end;
otherwise
if exist('fname', 'var') && exist('fext', 'var')
delete([fname fext]);
end
if exist('path_parent', 'var'), cd(path_parent); end
rethrow(exception);
end
if exist('path_parent', 'var'), cd(path_parent); end
end
res = errcode;
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/boxrotate.m | .m | 643 | 24 | function [ newloc,ind ] = boxrotate(loc,orig,fov)
%BOXROTATE Summary of this function goes here
% Detailed explanation goes here
shift = orig + fov/2;
thetaxy = -deg2rad(6.35);
thetaxz = -deg2rad(5.08);
dn = 0;
Rxy = [cos(thetaxy),-sin(thetaxy),0;sin(thetaxy),cos(thetaxy),0;0,0,1];
Rxz = [cos(thetaxz),0,sin(thetaxz);0,1,0;-sin(thetaxz),0,cos(thetaxz)];
ind = all(loc >= repmat(orig,size(loc,1),1),2)...
& all(loc <= repmat(orig + fov,size(loc,1),1),2);
newloc = loc(ind,:);
newloc = newloc - repmat(shift,size(newloc,1),1);
newloc = Rxy*newloc';
newloc = (Rxz*newloc)';
newloc = newloc + repmat(fov/2,size(newloc,1),1) + dn;
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/dispOrthoView.m | .m | 2,362 | 87 | function [h,hsub] = dispOrthoView(str_title,loc,gt,rad, varargin)
%Display an orthoview
% Either loc and gt are list of particle (frame, X, Y, Z)
% or cell containing the 3D image in the following way:
% {XYZ},{YZ},{XZ},{XY}
% When drawing rectangle, origin at bottom left
do2D = false;doRect = false;
k = 1;
while k < nargin - 4
switch varargin{k}
case 'cube'
pos = varargin{k+1}(1:end);
doRect = true;
case '2D'
do2D = varargin{k+1};
end
k = k + 2;
end
if iscell(loc)
if iscell(gt)
doScatter = false;
if doRect
if pos(3) < 0 %z component
pos(3) = pos(3) + pos(6)/2;%set z=0 as min val
end
pos(1:3) = pos(1:3) + 1;
pos(4:6) = pos(4:6) - 0.5;
end
else
fprintf('Inputs are not consistent\n');
return
end
else
doScatter = true;
end
h = figure('Name',str_title,'Color','black');
if ~do2D
hsub{1} = subplot(3,3,[1,2,4,5]);
end
if doScatter
scatter(loc(:,2), loc(:,3),rad,'r','filled');hold on;
scatter(gt(:,3),gt(:,4),rad,'g','filled');
else
im{1} = imfuse(loc{4},gt{4},'ColorChannels',[1,2,0],...
'Scaling','independent');hold on;
image(im{1});
end
if doRect
rectangle('Position',[pos([2,1]), pos(4:5)],'EdgeColor','w');
end
axis off;title('XY','Color','w','FontSize',14);
if ~do2D
hsub{2} = subplot(3,3,[7,8]);
if doScatter
scatter(loc(:,2), loc(:,4),rad,'r','filled');hold on;
scatter(gt(:,3),gt(:,5),rad,'g','filled');
else
im{2}=imfuse(loc{3}',gt{3}','ColorChannels',[1,2,0],...
'Scaling','independent');hold on;
image(im{2});
end
if doRect
rectangle('Position',[pos([1,3]), pos([4,6])],'EdgeColor','w');
end
axis off;title('XZ','Color','w','FontSize',14);
hsub{3} = subplot(3,3,[3,6]);
if doScatter
scatter(loc(:,4), loc(:,3),rad,'r','filled');hold on;
scatter(gt(:,5),gt(:,4),rad,'g','filled');
else
im{3}=imfuse(loc{2},gt{2},'ColorChannels',[1,2,0],...
'Scaling','independent');hold on;
image(im{3});
end
if doRect
rectangle('Position',[pos([3,2]), pos([6,5])],'EdgeColor','w');
end
axis off;title('YZ','Color','w','FontSize',14);
end
drawnow;
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/main_plot3D.m | .m | 7,115 | 246 | %% Load pairings file resulting from assessment program
clear pos
path = '~/Dropbox/smlm/figures/';
%Winners:
%2D LD 3D-DAOSTORM
%2D HD SMfit
%AS LD CSpline
%AS HD SMolPhot
%BP LD MIATool
%BP HD ThunderSTORM
%DH LD CSpline
%DH HD CSpline
software = 'CSpline';%'TVSTORM';%'CSpline';%'3D-WTM';%'MIATool-RMS';%'STORMChaser';
modality = 'AS';
dataset = 'MT3.N2.LD';
wobble = false;
photonT = true;
%File must be in the path
if wobble
fname = dir(fullfile('assessment_results',software,...
sprintf('pairings____%s____%s____%s____wobble_%s____border_450____photonT_*',...
dataset,modality,software,'beads')));
if isempty(fname)
fname = dir(fullfile('assessment_results',software,...
sprintf('pairings____%s____%s____%s____wobble_%s____border_450____photonT_*',...
dataset,modality,software,'file')));
end
if isempty(fname)
error('No file found');
end
else
fname = dir(fullfile('assessment_results',software,...
sprintf('pairings____%s____%s____%s____wobble_%s____border_450____photonT_*',...
dataset,modality,software,'no')));
end
iter = 0;
for kk = 1:length(fname)
if ~isempty(strfind(fname(kk - iter).name,'photonT_0_'))
fname(kk - iter) = [];
iter = iter + 1;
end
end
fname = fullfile('assessment_results',software,fname(1).name);
fprintf('Reading file %s\n',fname);
%%
[pos.frame,pos.x,pos.y,pos.z,pos.int] = importLocations(fname);
pos = struct2table(pos);
pos(isnan(pos.x),:) = [];
%% GT
clear gt
fname_gt = dir(fullfile('assessment_results','GT',...
sprintf('pairings____%s____%s____GT____wobble_no____border_450____photonT_*',...
dataset,modality)));
iter = 0;
for kk = 1:length(fname_gt)
if ~isempty(strfind(fname_gt(kk - iter).name,'photonT_0_'))
fname_gt(kk - iter) = [];
iter = iter + 1;
end
end
fname_gt = fullfile('assessment_results','GT',fname_gt(1).name);
fprintf('Reading file %s\n',fname_gt);
[gt.frame,gt.x,gt.y,gt.z,gt.int] = importLocations(fname_gt);
gt = struct2table(gt);
gt(isnan(gt.x),:) = [];
%%
center = false;
if center
fov = [6400,6400,1500];
elseif strcmpi(dataset,'MT1.N1.LD')
fov = [3000, 1200, 1500];%[500,1200,1500];%
elseif strcmpi(dataset,'MT2.N1.HD')
fov = [3000, 1200, 1500];
elseif strcmpi(dataset,'MT3.N2.LD')
fov = [1500, 1800, 1500];
elseif strcmpi(dataset,'MT4.N2.HD')
fov = [2400,2000,1500];%[1800,1500,1500];
end
pix_size = 2;%don't 1
imsize = fov/pix_size;
doCorr = 1;
sigmin = 10/(2*sqrt(2*log(2)));
sigmax = 10/(2*sqrt(2*log(2)));
thresmax = quantile(pos.int,0.95);
thresmin = quantile(pos.int,0.05);
sig = max(min((pos.int - thresmin)/(thresmax - thresmin),1),0);
sig = sigmax + (sigmin - sigmax).*sqrt(sig);
if center
shift = ([6400,6400,1500] - fov)/2;
elseif strcmpi(dataset,'MT1.N1.LD')
shift = [3000,2000,0];%[1650,4050,0];%
elseif strcmpi(dataset,'MT2.N1.HD')
shift = [3000,2000,0];
elseif strcmpi(dataset,'MT3.N2.LD')
shift = [3750,650,0];
elseif strcmpi(dataset,'MT4.N2.HD')
shift = [2600,1200,0];%[2200,4500,0];%MT4
end
vecx = (1:pix_size:fov(1)) + shift(1);
vecy = (1:pix_size:fov(2)) + shift(2);
vecz = (1:pix_size:fov(3)) + shift(3);
thresmax = quantile(gt.int,0.95);
thresmin = quantile(gt.int,0.05);
sig_gt = max(min((gt.int - thresmin)/(thresmax - thresmin),1),0);
sig_gt = sigmax + (sigmin - sigmax).*sqrt(sig_gt);
%% Get "density map" invers. prop. to sqrt(estimated intensity), see sig exp.
tic
im = gauss_render_intensity([pos.x,pos.y,pos.z] - repmat(shift,height(pos),1),sig, pix_size, imsize,doCorr);
toc
%% Display 2D XZ view
curr_im = squeeze(sum(im,2))';
figure;
imagesc(vecx,vecz, curr_im);colormap hot
title(sprintf('XZ view, %s %s %s',software,modality,dataset),'FontSize',16);
axis image;
%% XY
figure;
imagesc(vecx,vecy,sum(im,3));colormap hot;
title(sprintf('XY view, %s %s %s',software,modality,dataset),'FontSize',16);
axis image;
%% YZ
figure;
imagesc(vecy,vecz,squeeze(sum(im,1))');colormap hot;
title(sprintf('YZ view, %s %s %s',software,modality,dataset),'FontSize',16);
%caxis([quantile(curr_im(:),0.01),quantile(curr_im(:),0.999)])
axis image;
%% Get color coded depth (and display 3D as assessment
tic
[fig_h,circSize,color] = disp3D([pos.frame,pos.x,pos.y,pos.z,pos.int],...
sprintf('%s %s %s',dataset, software,modality),im,pix_size);
toc
%% Display 2D depth color coded
figure;
scatter(pos.x,pos.y,circSize,color);
axis off;
%print(fullfile(path,sprintf('%s-%s-%s.pdf',dataset,software,modality)),'-dpdf','-r0');
set(gcf, 'PaperUnits', 'centimeters');
set(gcf,'PaperPosition', [0 0 10 15]);
saveas(gcf,fullfile(path,sprintf('%s-%s-%s.pdf',dataset,software,modality)));
title(sprintf('%s %s %s',dataset, software,modality),'FontSize',16);
%% Render GT
tic
im_gt = gauss_render_intensity([gt.x,gt.y,gt.z] - repmat(shift,height(gt),1),...
sig_gt, pix_size, imsize,1);
toc
%%%
%[fig_h_gt,circSize_gt,color_gt] = disp3D([gt.frame,gt.x,gt.y,gt.z,gt.int]- repmat([0,shift,0],height(gt),1),'GT',im_gt,pix_size);
%% XZ GT
figure;
imagesc(squeeze(sum(im_gt,2))');colormap hot;
title(sprintf('XZ view, GT %s',dataset),'FontSize',16);
%axis image;
%% XY GT
figure;
imagesc(vecx,vecy,squeeze(sum(im_gt,3)));colormap hot;
title(sprintf('XY view, GT %s',dataset),'FontSize',16);
axis image;
%% YZ GT
figure;
imagesc(vecy,vecz,squeeze(sum(im_gt,1))');colormap hot;
title(sprintf('YZ view, GT %s',dataset),'FontSize',16);
axis image;
%% Disp GT
figure;
scatter(gt.x,gt.y,circSize_gt,color_gt);
title(sprintf('%s GT %s',dataset,modality),'FontSize',16);
axis off;
%% Slice of z
figure;
minz = -100;
maxz = 100;
ind_z = gt.z >= minz & gt.z <= maxz;
scatter3(gt.x(ind_z),gt.y(ind_z),gt.z(ind_z),5,'filled');
xlabel('X');ylabel('Y');zlabel('Z');
%%
figure;
scatter(newloc_gt(:,2),newloc_gt(:,3),20,...
[0*ones(ngt,1),...
(newloc_gt(:,1)-min(newloc_gt(:,1)))/(max(newloc_gt(:,1))-min(newloc_gt(:,1))),...
0*ones(ngt,1)],...
'filled');
hold on;
scatter(newloc(:,2),newloc(:,3),20,...
[(newloc(:,1)-min(newloc(:,1)))/(max(newloc(:,1))-min(newloc(:,1)))...
0*ones(ntest,1),0*ones(ntest,1)],...
'filled');
axis image;
%%
figure;
scatter3(newloc_gt(:,1),newloc_gt(:,2),newloc_gt(:,3),20,'filled','g');hold;%...
% [0*ones(ngt,1),...
% (gt.int(ind_box_gt,1)-min(gt.int(ind_box_gt,1)))/(max(gt.int(ind_box_gt,1))...
% -min(gt.int(ind_box_gt,1))),...
% 0*ones(ngt,1)],...
% 'filled');hold on;
scatter3(newloc(:,1),newloc(:,2),newloc(:,3),20,...
[(pos.int(ind_box,1)-quantile(pos.int(ind_box,1),0.05))/(quantile(pos.int(ind_box,1),0.95)...
-quantile(pos.int(ind_box,1),0.05)),...
0*ones(ntest,1),...
0*ones(ntest,1)],...
'filled');
%%
figure,imagesc(squeeze(sum(im_box,1)));axis image;
%%
tmp = gcf;
tmp_gca = tmp.CurrentAxes;
loops = 100;
inc_view = [360/loops,0];
F(loops) = struct('cdata',[],'colormap',[]);
tmp_gca.View = [-37.5,30];
figure(tmp);
for kk = 1:loops
tmp_gca.View = tmp_gca.View + inc_view;
drawnow;
F(kk) = getframe;
end
%%
v = VideoWriter(sprintf('~/Dropbox/smlm/figures/%s_%s_video.mp4',software,modality),'MPEG-4');
open(v)
writeVideo(v,F);
close(v) | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/gather_public.m | .m | 971 | 30 | %% Gather public.csv files to publics.csv
res_fold = 'assessment_results';
modality = {'AS','BP','DH','2D'};
folders = dir(res_fold);
folders = folders(4:end);
for k = 1:folders
for l = 1:length(modality)
fid = fopen([res_fold filesep folders(k) filesep modality{l}]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/save_in_parfor.m | .m | 315 | 12 | function save_in_parfor(fullname,struct2save)
%SAVEVAR To use save in parfor loop
% INPUTS
% fullname : full filename (no .mat at the end)
% struct2save : save all the fields as separate variable
% save violates transparency in parallel computing
save([fullname,'.mat'],'-struct','struct2save','-v7.3');
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/make_cmp.m | .m | 6,850 | 167 | res_all = readtable('assessment_results/results_all.csv');
for n = 1:length(res_all.Properties.VariableNames)
units.(res_all.Properties.VariableNames{n}) = [];
end
%Manual Setting
crit_oi = {'Wob_'};
Ncategories = 2;
%'DeltaX','DeltaY','FRC_xy','MAD_lat','SNR_xy','RMSE_lat','Jaccard','Correl_'
metric = {'Jaccard','RMSE_lat','FRC_xy','Correl_'};
color_code = 'Soft';
rad = 18; %for scatter
str_titles = {'Software','Dataset','Modality',...
'Photons Threshold','Wobble'};%must correspond to "criterions"
%latex friendly
units.Jaccard = '\%';
units.RMSE_lat = 'nm';
units.RMSE_axial = 'nm';
units.DeltaX = 'nm'; units.DeltaY = 'nm'; units.DeltaZ = 'nm';
units.FRC_xy = 'nm'; units.FRC_yz = 'nm'; units.FRC_xz = 'nm'; units.FSC = 'nm';
units.SNR_xy = 'dB'; units.SNR_yz = 'dB'; units.SNR_xz = 'dB'; units.SNR_xyz = 'dB';
units.MAD_lat = 'nm'; units.MAD_ax = 'nm';
%end of manual setting
criterions = {'Soft','Dataset','Modality','Photons','Wob_'};
str_lab = str_titles(~cellfun(@isempty,strfind(criterions, crit_oi)));
str_lab = str_lab{1};
criterions = criterions(cellfun(@isempty,strfind(criterions, crit_oi)));
switch length(crit_oi)
case 1
crit_oi = crit_oi{1};
clear str_cat
switch crit_oi
case 'Wob_'
str_cat{1} = {'beads','file'};
str_cat{2} = {'no'};
Ncategories = 2;
case 'Photons'
str_cat{1} = unique(res_all.(crit_oi));
str_cat{2} = 0;
str_cat{1}(ismember(str_cat{1}, str_cat{2})) = [];
Ncategories = 2;
otherwise
types = unique(res_all.(crit_oi));
for k = 1:length(types)
str_cat{k} = types(k);
end
end
categories = false(height(res_all), Ncategories);
for k = 1:Ncategories
categories(:,k) = ismember(res_all.(crit_oi), str_cat{k});
end
if Ncategories==2 %compare between 2 cases
valid_part = unique(res_all.Soft);
for k = 1:Ncategories
valid_part = intersect(valid_part, unique(res_all.Soft(categories(:,k))));
end
for k = 1:Ncategories
categories(:,k) = categories(:,k)...
& ismember(res_all.Soft, valid_part);
end
row_with = find(categories(:,1));
coupling = zeros(length(row_with),2);
coupling(:,1) = row_with;
G = zeros(height(res_all), length(criterions));
for c = 1:length(criterions)
if strcmp(criterions{c},'Photons')
G(:, c) = findgroups(res_all.(criterions{c})>0);
else
G(:, c) = findgroups(res_all.(criterions{c}));
end
end
for g = 1:size(coupling, 1)
ind = find(ismember(G, G(coupling(g,1),:),'rows'));
coupling(g,2) = ind(ind~=coupling(g,1));
end
types_color = unique(res_all.(color_code)(coupling(:)));
colors = squeeze(hsv2rgb(linspace(0,1-1/length(types_color),length(types_color)),...
ones(1,length(types_color)),ones(1,length(types_color))));
for m = 1:length(metric)
figure;
ax = axes;
maxMet = max([res_all.(metric{m})(coupling(:,1));res_all.(metric{m})(coupling(:,2))]);
minMet = min([res_all.(metric{m})(coupling(:,1));res_all.(metric{m})(coupling(:,2))]);
x = res_all.(metric{m})(coupling(:,1));
y = res_all.(metric{m})(coupling(:,2));
x_col = res_all.(color_code)(coupling(:,1));
y_col = res_all.(color_code)(coupling(:,2));
for s = 1:length(types_color)
x_tmp = x(cellfun(@(in) strcmp(in,types_color{s}),x_col));
y_tmp = y(cellfun(@(in) strcmp(in,types_color{s}),y_col));
scatter(x_tmp,y_tmp,rad,colors(s,:),'filled');%coupling shares same color_code normally
hold on;
end
legend(types_color,'Location','NorthWest');
plot(minMet:maxMet,minMet:maxMet,'black--');
str_tit = metric{m};
if any(strfind(str_tit,'_'))
str_tit = strcat('$',...
str_tit(1:strfind(str_tit,'_')),'{',...
str_tit(1+strfind(str_tit,'_'):end),'}$');
end
if ~isempty(units.(metric{m}))
str_tit = strcat(str_tit,' [',units.(metric{m}),']');
end
title(str_tit);
grid on;
xlabel(str_lab); ylabel(['No ', str_lab]);
axis([min(ax.XLim(1),ax.YLim(1)),max(ax.XLim(2),ax.YLim(2)),...
min(ax.XLim(1),ax.YLim(1)),max(ax.XLim(2),ax.YLim(2))]);
axis square tight
end
else %display for each category
for k = 1:Ncategories
for m = 1:length(metric)
figure;
ax = axes;
b = bar(res_all.(metric{m})(categories(:,k)));
emplac = 1;
ind_categ = find(categories(:,k));
for l = 2:nnz(categories(:,k))
emplac = [emplac; ~strcmp(cell2mat(res_all.Soft(ind_categ(l))),...
cell2mat(res_all.Soft(ind_categ(l-1))))];
end
emplac = [emplac; height(res_all)];
Ndatas = diff(find(emplac));
emplac = [0;cumsum(diff(find(emplac,nnz(emplac)-1)))] + Ndatas/2 + 0.5;
Ndatas = cumsum(Ndatas);
%b(1:Ndatas(1));
%for l = 2:length(Ndatas)
% b;
%end
ax.XTick = emplac;
ax.LineWidth = 0.001;
ax.FontSize = 9;
ax.XTickLabel = unique(res_all.Soft);
ax.XTickLabelRotation = 45;
str_tit = metric{m};
if any(strfind(str_tit,'_'))
str_tit = strcat('$',...
str_tit(1:strfind(str_tit,'_')),'{',...
str_tit(1+strfind(str_tit,'_'):end),'}$');
end
str_tit = strcat(str_tit,' [',units.(metric{m}),']');
title(str_tit);
xlabel(str_lab); ylabel(['No ', str_lab]);
end
end
end
case 2
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/getSigma.m | .m | 944 | 40 | function sig = getSigma(sigmin,sigmax,loc,k)
%GETSIGMA
%[V,C] = voronoin(unique(loc,'rows'));
%sig = zeros(length(C),1);
%for kk = 1:length(C)
%if isfinite(V(C{kk}))
%try
%[~,sig(kk)] = convhulln(V(C{kk},:));
%catch
% [~,sig(kk)] = convhulln(V(C{kk},:),{'Qt','Pp'});
% %fprintf('%i\n',kk);
%end
%else
% sig(kk) = inf;
%end
%end
Nmol = size(loc,1);
sig = zeros(Nmol,1);
tic
neigh = knnsearch([loc,(1:Nmol)'],[loc,(1:Nmol)'],'K',k,'Distance',@mycustomdist);
toc
for kk = 1:Nmol
X = loc(neigh(kk,:),:) - repmat(loc(kk,:),k,1);
sig(kk) = real(sqrt(det((X*X')/k)));
end
maxsig = quantile(sig,0.95);
minsig = quantile(sig,0.05);
sig = max(min((sig - minsig)/(maxsig - minsig),1),0);
sig = sigmin + (sigmax - sigmin).*sig;
end
function d2 = mycustomdist(zi,zj)
d2 = sum((repmat(zi(1:end-1),[size(zj,1),1]) - zj(:,1:end-1)).^2,2);
d2(zi(end)==zj(:,end)) = inf;
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/main_random.m | .m | 882 | 29 | clear fov
nframes = [151,19620,3020,20000,3125,20120,3020];
fov{1} = [12800,12800,1500];
fov{2} = [6400,6400,1500];
datasets = {'Beads','ER1.N3.LD','ER2.N3.HD','MT1.N1.LD',...
'MT2.N1.HD','MT3.N2.LD','MT4.N2.HD'};
mod = {'AS','2D','DH','BP','DHNPC'};
if ~exist('RANDOM','dir')
mkdir('RANDOM','upload');
end
for k = 1:length(datasets)
for l = 1:length(mod)
str = sprintf('%s____%s____RANDOM____RND.csv',datasets{k},mod{l});
if ~exist(fullfile('RANDOM','upload',str))
if strcmp(datasets{k},'Beads')
aveDens = 6;
curr_fov = fov{1};
else
aveDens = 20 - 18*isempty(strfind(datasets{k},'HD'));
curr_fov = fov{2};
end
loc = rnd_loc(aveDens, nframes(k), curr_fov);
csvwrite(sprintf('RANDOM/upload/%s',str),loc);
end
end
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/assessment_graph.m | .m | 25,736 | 492 | function out = assessment_graph(filenames,varargin)
%ASSESSMENT_GRAPH : Create distribution of GT & TP wrt various variables
%and with different settings; wobble and pairing criterion (2D or 3D) curr.
% Common features among compared results
% -One participant
% -One dataset
% -One modality
% -One intensity threshold (or not)
% Note : only minor changes are needed for multiparticipants, datasets,
% modalities, etc.
% Additional metrics are calculated from the distribution.
% varargin : 'RMSE' -> threshold to elicit an effective z-range for softw
% 'metrics' -> same for recall/precision/JAC rsp
% Written by Thanh-an Pham, 2016
global max_z_range
n=1;
fov = [6400,6400,1500];%nm
fold_path = 'assessment_results';
Nelements = 150;
Ylimit = 3e3;
%fold_all = 'comparatif';
Ylimits = [inf,120,150,1,1,100];%nm
%RMSE_thres = 50;%nm
exclusion = 450;%nm
metric_thres = [0.25,0.5;0.25,0.5;25,50];%one metric per row (several thresholds)
while n < nargin-1
switch varargin{n}
case 'fov'
fov = varargin{n+1};
case 'fold_path'
fold_path = varargin{n+1};
case 'Nelements'
Nelements = varargin{n+1};
case 'metrics'
metric_thres = varargin{n+1};
case 'Nsamples_smooth'
Nsamples_smooth = varargin{n+1};
case 'Alpha_smooth'
Alpha_smooth = varargin{n+1};
case 'Ylimit4rmse'
Ylimits = varargin{n+1};
case 'exclusion'
exclusion = varargin{n+1};
end
n = n+2;
end
Ndatasets = length(filenames);
dim3D = cell(Ndatasets,1);wobble = dim3D;wobble_orig = dim3D; photonT = dim3D; pairings = dim3D;
for kk=1:Ndatasets
pairings{kk} = csvread(filenames{kk});
wobble_orig{kk} = filenames{kk}(strfind(filenames{kk},'____wobble_')...
+11:strfind(filenames{kk},'____border_')-1);
if strcmp(wobble_orig{kk},'no')
wobble{kk} = 'no wobble';
else
wobble{kk} = 'wobble';
end
dim3D{kk} = str2double(filenames{kk}(strfind(filenames{kk},'____dim3D_')...
+10));
if dim3D{kk}
dim3D{kk} = '3D';
else
dim3D{kk} = '2D';
end
photonT{kk} = filenames{kk}(strfind(filenames{kk},'____photonT_')...
+12:strfind(filenames{kk},'____date')-1);
end
sep = strfind(filenames{1},'____');
dataset = filenames{1}(sep(1)+4:sep(2)-1);
modality = filenames{1}(sep(2)+4:sep(3)-1);
participant = filenames{1}(sep(3)+4:sep(4)-1);
save_folder = fullfile(fold_path,participant,'figures','statistics');
if ~exist(save_folder,'dir')...
|| ~exist(fullfile(save_folder,'eps'),'dir')...
|| ~exist(fullfile(save_folder,'png'),'dir')
mkdir(save_folder,'eps');
mkdir(save_folder,'png');
mkdir(save_folder,'data');
end
str_col = {'ID', 'X', 'Y', 'Z', 'Frame',...
'Photons', 'Channel', 'Frame ON', 'Total','Background Mean',...
'Background Stdev', 'Signal Mean', 'Signal Stdev','Signal Peak', 'Sigma X',...
'Sigma Y', 'Sigma Z', 'Uncertainty', 'Closest ID','Closest Distance',...
'Closest Count', 'CNR', 'SNR', 'PSNR','Unknown1',...
'Unknown2','Frame_loc','X_loc','Y_loc','Z_loc','Photons_loc'};
init_length = length(str_col);
out = print_fig('Z','Xlimits',[-fov(3)/2,fov(3)/2]);
print_fig('Photons','Xlimits',[0,inf]);
print_fig('SNR');
%print_fig('CNR');
%print_fig('PSNR');
%print_fig('Closest Distance','X-axis','log','Xlimits',[0,500]);%not useful
print_fig('CV','division','Signal Stdev','Signal Mean');
function out = print_fig(str_interest,varargin)
out = cell(Ndatasets,1);
meanRMSExy = out;meanRMSEz = out;horiz_vec4xy = out; horiz_vec4z = out;
for ii = 1:Ndatasets
out{ii}.modality = modality;
out{ii}.dataset = dataset;
out{ii}.participant = participant;
out{ii}.wobble = wobble_orig{ii};
out{ii}.photonT = str2double(photonT{ii});
out{ii}.metric_thres = metric_thres;
out{ii}.min_z_range_metric = nan(size(metric_thres));
out{ii}.max_z_range_metric = nan(size(metric_thres));
out{ii}.meanRMSExy_onRangeZ = nan(size(metric_thres));
out{ii}.stdRMSExy_onRangeZ = nan(size(metric_thres));
out{ii}.CVRMSExy_onRangeZ = nan(size(metric_thres));
out{ii}.meanRMSEz_onRangeZ = nan(size(metric_thres));
out{ii}.stdRMSEz_onRangeZ = nan(size(metric_thres));
out{ii}.CVRMSEz_onRangeZ = nan(size(metric_thres));
out{ii}.range_metric = nan(size(metric_thres));
out{ii}.max_metric = nan(3,1);
out{ii}.min_z_FWHM_metric = nan(3,1);
out{ii}.max_z_FWHM_metric = nan(3,1);
out{ii}.FWHM = nan(3,1);
end
for fig_iter = 1:(3 + strcmp(str_interest,'Z')...
*(1 + 2*(~strcmp(modality,'2D')))) %do TP, distance (~RMSE), (recall, (precision and JAC)*(3D))*Z
switch fig_iter
case 1
strLegend{1} = 'Ground Truth';
y_var = 'TP';
case 2
strLegend = [];
y_var = 'RMSEloc xy';
case 3
strLegend = [];
y_var = 'RMSEloc z';
case 4
strLegend = [];
y_var = 'Recall';
case 5
strLegend = [];
y_var = 'Precision';
case 6
strLegend = [];
y_var = 'Jaccard';
end
str_fname = sprintf('%s %s vs %s %s %s photons T %s',...
participant,y_var, str_interest,...
dataset,modality,photonT{1});
str_tit = str_fname;
str_tit(strfind(str_tit,'_')) = '-';
doLogx = false;
for ii=1:Ndatasets
k=1;
while k <= nargin-1
switch varargin{k}
case 'Xlimits'
Xlimits = varargin{k+1};
case 'step'
step = varargin{k+1};
case 'Ylimit'
Ylimit = varargin{k+1};
case 'X-axis'
if strcmp(varargin{k+1},'log')
doLogx = true;
end
case 'division' %create new column resulting from division between 2 columns
ind_var_up = ~cellfun(@isempty,strfind(str_col, varargin{k+1}))...
& cellfun(@length,str_col)==length(varargin{k+1});
ind_var_bottom = ~cellfun(@isempty,strfind(str_col, varargin{k+2}))...
& cellfun(@length,str_col)==length(varargin{k+2});
pairings{ii}(:,end+1) = pairings{ii}(:,ind_var_up)...
./pairings{ii}(:,ind_var_bottom);
ind_var = ~cellfun(@isempty,strfind(str_col, str_interest))...
& cellfun(@length,str_col)==length(str_interest);
if ~any(ind_var)
str_col{end+1} = str_interest;
end
k=k+1;
end
k=k+2;
end
ind_var = ~cellfun(@isempty,strfind(str_col, str_interest))...
& cellfun(@length,str_col)==length(str_interest);
if exist('Xlimits','var')
if isinf(Xlimits(1))
Xlimits(1) = min(pairings{ii}(:,ind_var));
elseif isinf(Xlimits(2))
Xlimits(2) = max(pairings{ii}(:,ind_var));
end
else
Xlimits = [min(pairings{ii}(:,ind_var)),...
max(pairings{ii}(:,ind_var))];
end
switch fig_iter
case 1
if ~exist('step','var')
step = diff(Xlimits)/Nelements;
end
case 2
Nelements4rmse = round(Nelements/3);
step = diff(Xlimits)/Nelements4rmse;
case 3
Nelements4rmse = round(Nelements/3);
step = diff(Xlimits)/Nelements4rmse;
otherwise
Nelements4others = round(Nelements/3);
step = diff(Xlimits)/Nelements4others;
end
horiz_vec = Xlimits(1):step:Xlimits(2);
switch fig_iter
case 1
var_countGT = histcounts(pairings{ii}(:,ind_var), horiz_vec);
var_countTested = histcounts(pairings{ii}(~isnan(pairings{ii}(:,init_length)),...
ind_var), horiz_vec);
Ystr = 'Fluorophore counts';
max_z_range(1) = horiz_vec(find(var_countGT,1,'first')) + step/2;
max_z_range(2) = horiz_vec(find(var_countGT,1,'last')) + step/2;
case 2
indXY = ~cellfun(@isempty,strfind(str_col, 'X')) & cellfun(@length,str_col)==1;
indXY = indXY | (~cellfun(@isempty,strfind(str_col, 'Y')) & cellfun(@length,str_col)==1);
indXYloc = ~cellfun(@isempty,strfind(str_col, 'X_loc')) & cellfun(@length,str_col)==5;
indXYloc = indXYloc | (~cellfun(@isempty,strfind(str_col, 'Y_loc')) & cellfun(@length,str_col)==5);
[~,~,binGT] = histcounts(pairings{ii}(:,ind_var), horiz_vec);
meanY = nan(Nelements4rmse,1); varY = meanY;
for m=1:Nelements4rmse
Y = sum((pairings{ii}(binGT==m,indXY) - pairings{ii}(binGT==m,indXYloc)).^2,2);
meanY(m) = sqrt(nanmean(Y));%RMSE = sqrt(sum(dist.^2)/TP)
varY(m) = nanstd(sqrt(Y));% a bit meaningless
end
finerStep = diff(Xlimits)/Nelements;
horiz_vec4xy{ii} = Xlimits(1):finerStep:Xlimits(2);%2do better formulation
[~,~,binGT] = histcounts(pairings{ii}(:,ind_var), horiz_vec4xy{ii});
meanRMSExy{ii} = nan(Nelements,1);
for m=1:Nelements
Y = sum((pairings{ii}(binGT==m,indXY) - pairings{ii}(binGT==m,indXYloc)).^2,2);
meanRMSExy{ii}(m) = sqrt(nanmean(Y));
end
horiz_vec4xy{ii} = horiz_vec4xy{ii}(1:end-1) + finerStep/2;
Ystr = 'RMSE$^{local}_{xy}$';
case 3
indZ = ~cellfun(@isempty,strfind(str_col, 'Z')) & cellfun(@length,str_col)==1;
indZloc = ~cellfun(@isempty,strfind(str_col, 'Z_loc')) & cellfun(@length,str_col)==5;
[~,~,binGT] = histcounts(pairings{ii}(:,ind_var), horiz_vec);
meanY = nan(Nelements4rmse,1); varY = meanY;
for m=1:Nelements4rmse
Y = (pairings{ii}(binGT==m,indZ) - pairings{ii}(binGT==m,indZloc)).^2;
meanY(m) = sqrt(nanmean(Y));
varY(m) = nanstd(sqrt(Y));%a bit meaningless
end
finerStep =diff(Xlimits)/Nelements;
horiz_vec4z{ii} = Xlimits(1):finerStep:Xlimits(2);%2do better formulation
[~,~,binGT] = histcounts(pairings{ii}(:,ind_var), horiz_vec4z{ii});
meanRMSEz{ii} = nan(Nelements,1);
for m=1:Nelements
Y = (pairings{ii}(binGT==m,indZ) - pairings{ii}(binGT==m,indZloc)).^2;
meanRMSEz{ii}(m) = sqrt(nanmean(Y));
end
horiz_vec4z{ii} = horiz_vec4z{ii}(1:end-1) + finerStep/2;
Ystr = 'RMSE$^{local}_{z}$';
otherwise
indPaired = ~isnan(pairings{ii}(:,init_length));
GT = histcounts(pairings{ii}(:,ind_var), horiz_vec);
TP = histcounts(pairings{ii}(indPaired,...
ind_var), horiz_vec);
FN = GT - TP;
%FP is only an approximate estimation per bin
Nfluor = dir(fullfile(participant,'standard',...
[filenames{ii}(sep(1)+4:sep(4)-1),'*']));
Nfluor = csvread(Nfluor.name);
Nfluor = Nfluor(Nfluor(:,2) > exclusion & Nfluor(:,3) > exclusion...
& Nfluor(:,2) < fov(1) - exclusion & Nfluor(:,3) < fov(2) - exclusion,:);
Nfluor = Nfluor(:,2:4);
indXYZloc = ~cellfun(@isempty,strfind(str_col, 'X_loc')) & cellfun(@length,str_col)==5;
indXYZloc = indXYZloc | (~cellfun(@isempty,strfind(str_col, 'Y_loc')) & cellfun(@length,str_col)==5);
indXYZloc = indXYZloc | (~cellfun(@isempty,strfind(str_col, 'Z_loc')) & cellfun(@length,str_col)==5);
if str2double(photonT{ii}) > 0
pairings_nonT = dir(fullfile(fold_path,participant,...
strcat(filenames{ii}(1:strfind(filenames{ii},'____photonT_')+11),'0*')));
pairings_nonT = csvread(fullfile(fold_path,participant,...
pairings_nonT.name));
FPind = ~ismember(Nfluor,pairings_nonT(:,indXYZloc),'rows');%rm the paired ones without photon thresholding (not part of FP)
else
FPind = ~ismember(Nfluor,pairings{ii}(indPaired,indXYZloc),'rows');%rm the paired ones (not part of FP)
end
FP = histcounts(Nfluor(FPind, end), horiz_vec);
switch fig_iter
case 4
metric = TP./GT;
Ystr = 'Recall';
case 5
metric = TP./(FP + TP);
Ystr = 'Precision';
case 6
metric = TP./(FN + FP + TP)*100;
Ystr = 'Jaccard';
end
metric(isinf(metric)) = nan;
if strcmp(str_interest,'Z') %4,5,6
metric_tmp = metric; metric_tmp(isnan(metric_tmp)) = 0;
smoothed_metric = conv(metric_tmp, gausswin(Nsamples_smooth,Alpha_smooth)'...
/sum(gausswin(Nsamples_smooth,Alpha_smooth)),'same');
%Range based on Threshold
for iter_T = 1:length(metric_thres(fig_iter-3,:))
inters = isect(horiz_vec(1:end-1), smoothed_metric,...
metric_thres(fig_iter-3,iter_T)*ones(size(smoothed_metric)))+ step/2;
if isempty(inters)
out{ii}.min_z_range_metric(fig_iter-3, iter_T) = 0;
out{ii}.max_z_range_metric(fig_iter-3, iter_T) = 0;
else
minZ = max(max_z_range(1),inters(1));
maxZ = min(max_z_range(2),inters(end));
out{ii}.min_z_range_metric(fig_iter-3, iter_T) = minZ;
out{ii}.max_z_range_metric(fig_iter-3, iter_T) = maxZ;
%calculate mean,std of RMSExy on this range
out{ii}.meanRMSExy_onRangeZ(fig_iter-3, iter_T) =...
nanmean(meanRMSExy{ii}(horiz_vec4xy{ii}>=minZ & horiz_vec4xy{ii}<=maxZ));
out{ii}.stdRMSExy_onRangeZ(fig_iter-3, iter_T) =...
nanstd(meanRMSExy{ii}(horiz_vec4xy{ii}>=minZ & horiz_vec4xy{ii}<=maxZ));
out{ii}.CVRMSExy_onRangeZ(fig_iter-3, iter_T) = ...
out{ii}.stdRMSExy_onRangeZ(fig_iter-3, iter_T)/out{ii}.meanRMSExy_onRangeZ(fig_iter-3, iter_T);
%calculate mean,std of RMSEz on this range
out{ii}.meanRMSEz_onRangeZ(fig_iter-3, iter_T) =...
nanmean(meanRMSEz{ii}(horiz_vec4z{ii}>=minZ & horiz_vec4z{ii}<=maxZ));
out{ii}.stdRMSEz_onRangeZ(fig_iter-3, iter_T) =...
nanstd(meanRMSEz{ii}(horiz_vec4z{ii}>=minZ & horiz_vec4z{ii}<=maxZ));
out{ii}.CVRMSEz_onRangeZ(fig_iter-3, iter_T) = ...
out{ii}.stdRMSEz_onRangeZ(fig_iter-3, iter_T)/out{ii}.meanRMSEz_onRangeZ(fig_iter-3, iter_T);
end
out{ii}.range_metric(fig_iter-3, iter_T)=...
out{ii}.max_z_range_metric(fig_iter-3, iter_T)...
-out{ii}.min_z_range_metric(fig_iter-3, iter_T);
end
%FWHM on smoothed
out{ii}.max_metric(fig_iter-3) = max(smoothed_metric);
inters = isect(horiz_vec(1:end-1), smoothed_metric,...
max(metric)/2*ones(size(smoothed_metric))) + step/2;
if isempty(inters) %should never happen, in case, assume too perfect
fprintf('Should never happen except GT : %s\n',participant);
out{ii}.min_z_FWHM_metric(fig_iter-3) = max_z_range(1);
out{ii}.max_z_FWHM_metric(fig_iter-3) = max_z_range(2);
else
out{ii}.min_z_FWHM_metric(fig_iter-3) = max(max_z_range(1), inters(1));
out{ii}.max_z_FWHM_metric(fig_iter-3) = min(max_z_range(2), inters(end));
end
out{ii}.FWHM(fig_iter-3) =...
out{ii}.max_z_FWHM_metric(fig_iter-3)...
-out{ii}.min_z_FWHM_metric(fig_iter-3);
end
end
horiz_vec = horiz_vec(1:end-1) + step/2;
if ~exist('fig','var')
fig = figure;
switch fig_iter
case 1
if doLogx
h{1} = semilogx(horiz_vec, var_countGT,...
'Color',[0.4660,0.6740,0.1880]);
else
h{1} = plot(horiz_vec, var_countGT,...
'Color',[0.4660,0.6740,0.1880]);
end
otherwise
h = [];
end
smoothed_plot = [];
hold on;
xlabel(str_interest);ylabel(Ystr);
title(str_tit);
axes_main = gca;
end
switch fig_iter
case 1
if doLogx
h{end+1} = semilogx(axes_main,horiz_vec, var_countTested);
else
h{end+1} = plot(axes_main,horiz_vec, var_countTested);
end
case {2,3}
%h{end+1} = errorbar(axes_main,horiz_vec,meanY,varY);
h{end+1} = plot(axes_main,horiz_vec, meanY);%meanYplot
otherwise %only if Z variable
h{end+1} = plot(axes_main, horiz_vec, metric);
if exist('smoothed_metric','var')
smoothed_plot{end+1} = plot(axes_main, horiz_vec,...
smoothed_metric,'LineWidth',2);
end
end
switch [wobble{ii}, dim3D{ii}]
case 'no wobble3D'
set(h{end},'Color',[0,0.4470,0.7410],...
'LineStyle','-');%pretty dark blue
case 'no wobble2D'
set(h{end},'Color',[0.3010,0.7450,0.9330]);%pretty light blue
case 'wobble3D'
set(h{end},'Color',[0.6350,0.0780,0.1840],...
'LineStyle','-');%pretty dark red
case 'wobble2D'
set(h{end},'Color',[0.8500,0.3250,0.0980]);%pretty light red/orange
end
switch fig_iter
case 1
strLegend{end+1} = sprintf('%s - %s %s', y_var, wobble{ii},dim3D{ii});
case {2,3}
%set(meanYplot, 'Color', h{end}.Color,'LineStyle',h{end}.LineStyle);
strLegend{end+1} = sprintf('%s - %s %s', Ystr([1:4,6:end-1]), wobble{ii},dim3D{ii});
otherwise
if exist('smoothed_plot','var')
set(smoothed_plot{end}, 'Color', h{end}.Color,'LineStyle','--');
end
strLegend{end+1} = sprintf('%s - %s %s', Ystr, wobble{ii},dim3D{ii});
end
if ii==Ndatasets
legend(cat(1,h{:}), strLegend);
end
if fig_iter > 1 || max(var_countGT) < Ylimit
axis([horiz_vec([1,end]),0,Ylimits(fig_iter)]);
%axis([horiz_vec([1,end]),0,inf]);
%axis 'auto y'
else
axis(axes_main,[horiz_vec([1,end]),0,Ylimit]);
plot(axes_main,horiz_vec(var_countGT>Ylimit),Ylimit,'bp');
windowSize = round(length(horiz_vec)/5);
b = (1/windowSize)*ones(1, windowSize);
[~, pos] = min(filter(b,1,var_countGT));
if ~exist('axes_zoom','var')
axes_zoom = axes('position',...
[max(min(pos/length(horiz_vec),0.6),0.2) .5 .25 .25]);
xlabel(str_interest);ylabel('Fluorophores count');
box on;hold on;
xvalGT = [];yvalGT = [];xvalTe = [];yvalTe = [];
end
indOI = var_countGT > Ylimit;
xvalGT = [xvalGT, horiz_vec(indOI)];
yvalGT = [yvalGT, var_countGT(indOI)];
xvalTe = [xvalTe, horiz_vec(indOI)];
yvalTe = [yvalTe, var_countTested(indOI)];
if ii==Ndatasets
semilogy(axes_zoom, xvalGT,yvalGT,'bp',...
xvalTe,yvalTe,'rp');
legend('GT','TP');
end
end
end
if exist('axes_zoom','var')
axis(axes_zoom, 'tight');
end
Yhandle = get(fig.Children,'Children'); Yhandle = Yhandle{2};
YData = zeros(length(horiz_vec),length(Yhandle));
for Yiter = 1:length(Yhandle)
YData(:,Yiter) = Yhandle(Yiter).YData;
end
dlmwrite(fullfile(save_folder,'data',[str_fname,'.csv']),[horiz_vec',YData],'precision',8);
print(fig,'-depsc',fullfile(save_folder,...
'eps',[str_fname,'.eps']));
print(fig,'-dpng',fullfile(save_folder,...
'png',[str_fname,'.png']));
%public, do not save {RMSExy,z} vs {SNR, CV}
%NEITHER RMSEz vs (any) when 2D
%AND rm the smoothed version for public
if ~isempty(smoothed_plot)
for iterS=1:length(smoothed_plot)
delete(smoothed_plot{iterS});
end
%to be sure
axis([horiz_vec([1,end]),0,Ylimits(fig_iter)]);
end
if (~any(strcmpi(str_interest,{'SNR','CV'})) || (fig_iter~=2 && fig_iter~=3))...
&& ~(strcmp(modality,'2D') && fig_iter==3)
print(fig,'-dpng',fullfile(fold_path, participant,...
modality, 'png', [str_fname,'.png']));
dlmwrite(fullfile(fold_path, participant, modality,...
'data',[str_fname,'.csv']),[horiz_vec',YData],'precision',8);
end
close(fig)
clear fig h strLegend axes_zoom meanYplot p z_range smoothed_metric smoothed_plot YData
end
end
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/assessment_graph_old.m | .m | 20,600 | 414 | function out = assessment_graph_old(filenames,varargin)
%ASSESSMENT_GRAPH : Create distribution of GT & TP wrt various variables
%and with different settings; wobble and pairing criterion (2D or 3D) curr.
% Common features among compared results
% -One participant
% -One dataset
% -One modality
% -One intensity threshold (or not)
% Note : only minor changes are needed for multiparticipants, datasets,
% modalities, etc.
% Additional metrics are calculated from the distribution.
% varargin : 'RMSE' -> threshold to elicit an effective z-range for softw
% 'metrics' -> same for recall/precision/JAC rsp
% Written by Thanh-an Pham, 2016
n=1;
fov = [6400,6400,1500];%nm
fold_path = 'assessment_results';
Nelements = 150;
Ylimit = 2.5e3;
RMSE_thres = 50;%nm
metric_thres = [0.5,0.5,0.4];
while n < nargin-1
switch varargin{n}
case 'fov'
fov = varargin{n+1};
case 'fold_path'
fold_path = varargin{n+1};
case 'Nelements'
Nelements = varargin{n+1};
case 'RMSE'
RMSE_thres = varargin{n+1};
case 'metrics'
metric_thres = varargin{n+1};
end
n = n+2;
end
Ndatasets = length(filenames);
dim3D = cell(Ndatasets,1);wobble = dim3D;wobble_orig = dim3D; photonT = dim3D; pairings = dim3D;
for kk=1:Ndatasets
pairings{kk} = csvread(filenames{kk});
wobble_orig{kk} = filenames{kk}(strfind(filenames{kk},'____wobble_')...
+11:strfind(filenames{kk},'____border_')-1);
if strcmp(wobble_orig{kk},'no')
wobble{kk} = 'no wobble';
else
wobble{kk} = 'wobble';
end
dim3D{kk} = str2double(filenames{kk}(strfind(filenames{kk},'____dim3D_')...
+10));
if dim3D{kk}
dim3D{kk} = '3D';
else
dim3D{kk} = '2D';
end
photonT{kk} = filenames{kk}(strfind(filenames{kk},'____photonT_')...
+12:strfind(filenames{kk},'____date')-1);
end
sep = strfind(filenames{1},'____');
dataset = filenames{1}(sep(1)+4:sep(2)-1);
modality = filenames{1}(sep(2)+4:sep(3)-1);
participant = filenames{1}(sep(3)+4:sep(4)-1);
save_folder = fullfile(fold_path,participant,'figures','statistics');
if ~exist(save_folder,'dir')...
|| ~exist(fullfile(save_folder,'eps'),'dir')...
|| ~exist(fullfile(save_folder,'png'),'dir')
mkdir(save_folder,'eps');
mkdir(save_folder,'png');
end
str_col = {'ID', 'X', 'Y', 'Z', 'Frame',...
'Photons', 'Channel', 'Frame ON', 'Total','Background Mean',...
'Background Stdev', 'Signal Mean', 'Signal Stdev','Signal Peak', 'Sigma X',...
'Sigma Y', 'Sigma Z', 'Uncertainty', 'Closest ID','Closest Distance',...
'Closest Count', 'CNR', 'SNR', 'PSNR','Unknown1',...
'Unknown2','Frame_loc','X_loc','Y_loc','Z_loc','Photons_loc'};
init_length = length(str_col);
out = print_fig('Z','Xlimits',[-fov(3)/2,fov(3)/2]);
print_fig('Photons','Xlimits',[0,inf]);
print_fig('SNR');
%print_fig('CNR');
%print_fig('PSNR');
%print_fig('Closest Distance','X-axis','log','Xlimits',[0,500]);%not useful
print_fig('CV','division','Signal Stdev','Signal Mean');
function out = print_fig(str_interest,varargin)
out = cell(Ndatasets,1);
for ii = 1:Ndatasets
out{ii}.max_metric = nan(3,1);
out{ii}.z_max_metric = nan(3,1);
out{ii}.max_fitted = nan(3,1);
out{ii}.z_max_fitted = nan(3,1);
out{ii}.FWHM = nan(3,1);
out{ii}.z_range_FWHM = nan(3,2);
out{ii}.z_range_T_metric = nan(3,2);
out{ii}.FWHM_T = nan(3,1);
out{ii}.modality = modality;
out{ii}.dataset = dataset;
out{ii}.participant = participant;
out{ii}.wobble = wobble_orig{ii};
out{ii}.photonT = str2double(photonT{ii});
out{ii}.RMSE_thres = RMSE_thres;
out{ii}.metric_thres = metric_thres;
end
for fig_iter = 1:(3 + strcmp(str_interest,'Z')...
*(1 + 2*(~strcmp(modality,'2D')))) %do TP, distance (~RMSE), recall, (precision and JAC)*(3D)
switch fig_iter
case 1
strLegend{1} = 'Ground Truth';
y_var = 'TP';
case 2
strLegend = [];
y_var = 'RMSEloc xy';
case 3
strLegend = [];
y_var = 'RMSEloc z';
case 4
strLegend = [];
y_var = 'Recall';
case 5
strLegend = [];
y_var = 'Precision';
case 6
strLegend = [];
y_var = 'Jaccard';
end
str_fname = sprintf('%s %s vs %s %s %s photons T %s',...
participant,y_var, str_interest,...
dataset,modality,photonT{1});
str_tit = str_fname;
str_tit(strfind(str_tit,'_')) = '-';
doLogx = false;
for ii=1:Ndatasets
k=1;
while k <= nargin-1
switch varargin{k}
case 'Xlimits'
Xlimits = varargin{k+1};
case 'step'
step = varargin{k+1};
case 'Ylimit'
Ylimit = varargin{k+1};
case 'X-axis'
if strcmp(varargin{k+1},'log')
doLogx = true;
end
case 'division' %create new column resulting from division between 2 columns
ind_var_up = ~cellfun(@isempty,strfind(str_col, varargin{k+1}))...
& cellfun(@length,str_col)==length(varargin{k+1});
ind_var_bottom = ~cellfun(@isempty,strfind(str_col, varargin{k+2}))...
& cellfun(@length,str_col)==length(varargin{k+2});
pairings{ii}(:,end+1) = pairings{ii}(:,ind_var_up)...
./pairings{ii}(:,ind_var_bottom);
ind_var = ~cellfun(@isempty,strfind(str_col, str_interest))...
& cellfun(@length,str_col)==length(str_interest);
if ~any(ind_var)
str_col{end+1} = str_interest;
end
k=k+1;
end
k=k+2;
end
ind_var = ~cellfun(@isempty,strfind(str_col, str_interest))...
& cellfun(@length,str_col)==length(str_interest);
if exist('Xlimits','var')
if isinf(Xlimits(1))
Xlimits(1) = min(pairings{ii}(:,ind_var));
elseif isinf(Xlimits(2))
Xlimits(2) = max(pairings{ii}(:,ind_var));
end
else
Xlimits = [min(pairings{ii}(:,ind_var)),...
max(pairings{ii}(:,ind_var))];
end
switch fig_iter
case 1
if ~exist('step','var')
step = diff(Xlimits)/Nelements;
end
case 2
Nelements4rmse = round(Nelements/3);
step = diff(Xlimits)/Nelements4rmse;
case 3
Nelements4rmse = round(Nelements/3);
step = diff(Xlimits)/Nelements4rmse;
otherwise
Nelements4others = round(Nelements/3);
step = diff(Xlimits)/Nelements4others;
end
horiz_vec = Xlimits(1):step:Xlimits(2);
switch fig_iter
case 1
var_countGT = histcounts(pairings{ii}(:,ind_var), horiz_vec);
var_countTested = histcounts(pairings{ii}(~isnan(pairings{ii}(:,init_length)),...
ind_var), horiz_vec);
Ystr = 'Fluorophore counts';
case 2
[~,~,binGT] = histcounts(pairings{ii}(:,ind_var), horiz_vec);
indXY = ~cellfun(@isempty,strfind(str_col, 'X')) & cellfun(@length,str_col)==1;
indXY = indXY | (~cellfun(@isempty,strfind(str_col, 'Y')) & cellfun(@length,str_col)==1);
indXYloc = ~cellfun(@isempty,strfind(str_col, 'X_loc')) & cellfun(@length,str_col)==5;
indXYloc = indXYloc | (~cellfun(@isempty,strfind(str_col, 'Y_loc')) & cellfun(@length,str_col)==5);
meanY = nan(Nelements4rmse,1); varY = meanY;
for m=1:Nelements4rmse
Y = sqrt(sum((pairings{ii}(binGT==m,indXY) - pairings{ii}(binGT==m,indXYloc)).^2,2));
meanY(m) = nanmean(Y);
varY(m) = nanstd(Y);
end
Ystr = 'RMSE$^{local}_{xy}$';
case 3
[~,~,binGT] = histcounts(pairings{ii}(:,ind_var), horiz_vec);
indZ = ~cellfun(@isempty,strfind(str_col, 'Z')) & cellfun(@length,str_col)==1;
indZloc = ~cellfun(@isempty,strfind(str_col, 'Z_loc')) & cellfun(@length,str_col)==5;
meanY = nan(Nelements4rmse,1); varY = meanY;
for m=1:Nelements4rmse
Y = sqrt(sum((pairings{ii}(binGT==m,indZ) - pairings{ii}(binGT==m,indZloc)).^2,2));
meanY(m) = nanmean(Y);
varY(m) = nanstd(Y);
end
Ystr = 'RMSE$^{local}_{z}$';
otherwise
indPaired = ~isnan(pairings{ii}(:,init_length));
GT = histcounts(pairings{ii}(:,ind_var), horiz_vec);
TP = histcounts(pairings{ii}(indPaired,...
ind_var), horiz_vec);
FN = GT - TP;
%FP is only an approximate estimation per bin
Nfluor = dir(fullfile(participant,'standard',...
[filenames{ii}(sep(1)+4:sep(4)-1),'*']));
Nfluor = csvread(Nfluor.name); Nfluor = Nfluor(:,2:4);
indXYZloc = ~cellfun(@isempty,strfind(str_col, 'X_loc')) & cellfun(@length,str_col)==5;
indXYZloc = indXYZloc | (~cellfun(@isempty,strfind(str_col, 'Y_loc')) & cellfun(@length,str_col)==5);
indXYZloc = indXYZloc | (~cellfun(@isempty,strfind(str_col, 'Z_loc')) & cellfun(@length,str_col)==5);
FPind = ~ismember(Nfluor,pairings{ii}(indPaired,indXYZloc),'rows');%rm the paired ones from FP estimation
FP = histcounts(Nfluor(FPind, end), horiz_vec);
switch fig_iter
case 4
metric = TP./GT;
Ystr = 'Recall';
case 5
metric = TP./(FP + TP);
Ystr = 'Precision';
case 6
metric = TP./(FN + FP + TP)*100;
Ystr = 'Jaccard';
end
metric(isinf(metric)) = nan;
end
horiz_vec = horiz_vec(1:end-1) + step/2;
if ~exist('fig','var')
fig = figure;
switch fig_iter
case 1
if doLogx
h{1} = semilogx(horiz_vec, var_countGT,...
'Color',[0.4660,0.6740,0.1880]);
else
h{1} = plot(horiz_vec, var_countGT,...
'Color',[0.4660,0.6740,0.1880]);
end
otherwise
h = [];
end
fitH = [];
hold on;
xlabel(str_interest);ylabel(Ystr);
title(str_tit);
axes_main = gca;
end
switch fig_iter
case 1
if doLogx
h{end+1} = semilogx(axes_main,horiz_vec, var_countTested);
else
h{end+1} = plot(axes_main,horiz_vec, var_countTested);
end
case 2
h{end+1} = errorbar(axes_main,horiz_vec,meanY,varY);
meanYplot = plot(axes_main,horiz_vec,meanY,'LineWidth',2);
if strcmp(str_interest,'Z')
p = polyfit(horiz_vec(~isnan(meanY))',...
meanY(~isnan(meanY)), 2);
curve_fit = polyval(p, horiz_vec);
fitH{end+1} = plot(horiz_vec, curve_fit, 'black--','LineWidth',1);
out{ii}.z_min_fitted = -p(2)/(2*p(1));
out{ii}.min_fitted = polyval(p, -p(2)/(2*p(1)));%min parabole
[out{ii}.min_RMSE, out{ii}.z_min_RMSE] = min(meanY);
out{ii}.z_min_RMSE = horiz_vec(out{ii}.z_min_RMSE);
out{ii}.z_range_FWDM = sort(roots([p(1:2),...
p(3) - 2*out{ii}.min_RMSE]));%Full Width Double Minimum
if any(imag(out{ii}.z_range_FWDM))%complex => min_RMSE never reached
out{ii}.z_range_FWDM = nan(2,1);
end
if p(1) > 0 %smiling" parabola
out{ii}.z_range_FWDM_fitted = sort(roots([p(1:2),...
p(3) - 2*out{ii}.min_fitted]));%Full Width Double Minimum fitted
out{ii}.z_range_T_RMSE = sort(roots([p(1:2),p(3) - RMSE_thres]));%threshold
else %meaningless FWDM
out{ii}.z_range_FWDM = nan(2,1);
out{ii}.z_range_T_RMSE = nan(2,1);
out{ii}.z_range_FWDM_fitted = nan(2,1);
end
out{ii}.FWDM_fitted = abs(diff(out{ii}.z_range_FWDM_fitted));
out{ii}.FWDM_T = abs(diff(out{ii}.z_range_T_RMSE));
out{ii}.FWDM = abs(diff(out{ii}.z_range_FWDM));
end
case 3
h{end+1} = errorbar(axes_main,horiz_vec,meanY,varY);
meanYplot = plot(axes_main,horiz_vec,meanY,'LineWidth',2);
otherwise %only if Z variable
h{end+1} = plot(axes_main, horiz_vec, metric);
fitted_gauss = fit(horiz_vec(~isnan(metric))', metric(~isnan(metric))','gauss1');
coeff = coeffvalues(fitted_gauss);
FWHM = 2*coeff(3)*sqrt(log(2));%see fitted gaussian formula in matlab
z_range_fwhm = sort([coeff(2) - FWHM/2, coeff(2) + FWHM/2]);
z_range_thres = sort([coeff(2) + coeff(3)*sqrt(log(coeff(1)/metric_thres(fig_iter-2))),...
coeff(2) - coeff(3)*sqrt(log(coeff(1)/metric_thres(fig_iter-2)))]);
fitH{end+1} = plot(horiz_vec,feval(fitted_gauss,horiz_vec), 'black--','LineWidth',1);
out{ii}.max_fitted(fig_iter-2) = coeff(1);
out{ii}.z_max_fitted(fig_iter-2) = coeff(2);
[out{ii}.max_metric(fig_iter-2),out{ii}.z_max_metric(fig_iter-2)] = max(metric);
out{ii}.z_max_metric(fig_iter-2) = horiz_vec(out{ii}.z_max_metric(fig_iter-2));
out{ii}.FWHM(fig_iter-2) = FWHM;
out{ii}.z_range_FWHM(fig_iter-2,:) = z_range_fwhm;
out{ii}.z_range_T_metric(fig_iter-2,:) = z_range_thres;
out{ii}.FWHM_T(fig_iter-2) = abs(diff(z_range_thres));
end
switch [wobble{ii}, dim3D{ii}]
case 'no wobble3D'
set(h{end},'Color',[0,0.4470,0.7410],...
'LineStyle','-');%pretty dark blue
case 'no wobble2D'
set(h{end},'Color',[0.3010,0.7450,0.9330]);%pretty light blue
case 'wobble3D'
set(h{end},'Color',[0.6350,0.0780,0.1840],...
'LineStyle','-');%pretty dark red
case 'wobble2D'
set(h{end},'Color',[0.8500,0.3250,0.0980]);%pretty light red/orange
end
switch fig_iter
case 1
strLegend{end+1} = sprintf('%s - %s %s', y_var, wobble{ii},dim3D{ii});
case 2
set(meanYplot, 'Color', h{end}.Color,'LineStyle',h{end}.LineStyle);
strLegend{end+1} = sprintf('%s - %s %s', Ystr([1:4,6:end-1]), wobble{ii},dim3D{ii});
case 3
set(meanYplot, 'Color', h{end}.Color,'LineStyle',h{end}.LineStyle);
strLegend{end+1} = sprintf('%s - %s %s', Ystr([1:4,6:end-1]), wobble{ii},dim3D{ii});
otherwise
strLegend{end+1} = sprintf('%s - %s %s', Ystr, wobble{ii},dim3D{ii});
end
if ii==Ndatasets
legend(cat(1,h{:}), strLegend);
end
if fig_iter > 1 || max(var_countGT) < Ylimit
axis([horiz_vec([1,end]),0,inf]);
%axis 'auto y'
else
axis(axes_main,[horiz_vec([1,end]),0,Ylimit]);
plot(axes_main,horiz_vec(var_countGT>Ylimit),Ylimit,'bp');
windowSize = round(length(horiz_vec)/5);
b = (1/windowSize)*ones(1, windowSize);
[~, pos] = min(filter(b,1,var_countGT));
if ~exist('axes_zoom','var')
axes_zoom = axes('position',...
[max(min(pos/length(horiz_vec),0.6),0.2) .5 .25 .25]);
xlabel(str_interest);ylabel('Fluorophores count');
box on;hold on;
xvalGT = [];yvalGT = [];xvalTe = [];yvalTe = [];
end
indOI = var_countGT > Ylimit;
xvalGT = [xvalGT, horiz_vec(indOI)];
yvalGT = [yvalGT, var_countGT(indOI)];
xvalTe = [xvalTe, horiz_vec(indOI)];
yvalTe = [yvalTe, var_countTested(indOI)];
if ii==Ndatasets
semilogy(axes_zoom, xvalGT,yvalGT,'bp',...
xvalTe,yvalTe,'rp');
legend('GT','TP');
end
end
end
if exist('axes_zoom','var')
axis(axes_zoom, 'tight');
end
print(fig,'-depsc',fullfile(save_folder,...
'eps',[str_fname,'.eps']));
print(fig,'-dpng',fullfile(save_folder,...
'png',[str_fname,'.png']));
if ~isempty(fitH)
for iterH=1:length(fitH)
delete(fitH{iterH});
end
axis([horiz_vec([1,end]),0,inf]);
end
if ~any(strcmpi(str_interest,{'SNR','CV'})) || fig_iter~=2
print(fig,'-dpng',fullfile(fold_path, participant,...
modality, 'png', [str_fname,'.png']));
end
close(fig)
clear fig h strLegend axes_zoom meanYplot p z_range fitH
end
end
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/disp3D.m | .m | 3,550 | 84 | function [fig,circSize,color,loc] = disp3D(loc,str_title,im3D,pix_siz)
%im3D (3D gaussian rendered localizations) and pix_siz will define circle
doProj = [true,false];
maxSize = 6;
minSize = 2;
fig = cell(2,1);
for imType = 1:2
sizIm = size(im3D);
fov = sizIm*pix_siz;
corrZ = fov(3)/2;
ind_rm = loc(:,2) < 0 | loc(:,2) > fov(1) |...
loc(:,3) < 0 | loc(:,3) > fov(2) |...
loc(:,4) < -corrZ | loc(:,4) > fov(3) - corrZ;
loc(ind_rm,:) = [];
Nel = size(loc,1);
circSize = zeros(Nel,1);
for k=1:Nel
circSize(k) = im3D(1 + max(min(floor(loc(k,2)/pix_siz), sizIm(1)-1),0),...
1 + max(min(floor(loc(k,3)/pix_siz), sizIm(2)-1),0),...
1 + max(min((corrZ + floor(loc(k,4))/pix_siz), sizIm(3)-1),0));
end
maxVal = max(circSize) + (max(circSize)==0)*1;
circSize = (maxSize-minSize)*log10(1 + 99*circSize/maxVal)/log10(100) + minSize;%(1 - exp(-circSize/max(circSize)));
color = squeeze(hsv2rgb((loc(:,4)-min(loc(:,4)))/(max(loc(:,4)-min(loc(:,4)))),...
ones(Nel,1),ones(Nel,1)));
%colorPlane = squeeze(hsv2rgb((gt(:,4)-min(gt(:,4)))/(max(gt(:,4)-min(gt(:,4)))),...
%ones(res.nloc_gt_initial,1),0.2*ones(res.nloc_gt_initial,1)));
colorPlane = 'w';
fig{imType} = figure;
whitebg(fig{imType});
if doProj(imType)
%xz plane,-100 + min(loc(:,2))*
scatter3(zeros(Nel,1),loc(:,3),loc(:,4),circSize,colorPlane,'filled');hold on;
%yz plane-100 + min(loc(:,1))*
scatter3(loc(:,2),...
zeros(Nel,1),loc(:,4),circSize,colorPlane,'filled');
%z plane
scatter3(loc(:,2),loc(:,3),-fov(3)/2*ones(Nel,1),circSize,colorPlane,'filled');
end
%3D
scatter3(loc(:,2),loc(:,3),loc(:,4), circSize, color, 'filled');hold on;
if doProj(imType)
zAx = -fov(3)/2:max(fov(3)/2,max(loc(:,4)));
plot3(zeros(length(zAx),1),zeros(length(zAx),1),zAx,'w','LineWidth',1.5);
set(gca,'xtick',linspace(0,max(loc(:,2)),10));
set(gca,'ytick',linspace(0,max(loc(:,3)),10));
set(gca,'ztick',unique([linspace(zAx(1),0,5), linspace(0,zAx(end),5)]))
else
zAx = -fov(3)/2:max(fov(3)/2,max(loc(:,4)));
plot3(zeros(length(zAx),1),zeros(length(zAx),1),zAx,'w','LineWidth',1.5);
end
curr_ax = gca;
set(curr_ax,'Ydir','reverse','Xdir','reverse');
set(curr_ax,'LineWidth',1.5,'YAxisLocation','origin','XAxisLocation','origin',...
'xticklabel',{[]},'yticklabel',{[]},'zticklabel',{[]});
title(str_title);hold off;
grid on
if doProj(imType) %improve by getting positions of xlabel before xticklabel set off
%text(3953.8699714910617,6191.461925112759,-333.8702107707759,'X');
%text(6305.590234897347,3771.309889470256,-361.34195007938615,'Y');
%text(6798.014514492112,-319.45371226913994,512.4110141202436,'Z');
text(3903.998118570962,6354.910704097885,-1034.204448664219,'X');
text(6474.1412913783715,3758.0686139824684,-1073.1666362493488,'Y');
text(6801.183338021612,-378.47701227403013,224.90072171690554,'Z');
else
text(3903.998118570962,6354.910704097885,-1034.204448664219,'X');
text(6474.1412913783715,3758.0686139824684,-1073.1666362493488,'Y');
text(6801.183338021612,-378.47701227403013,224.90072171690554,'Z');
end
axis tight;
curr_ax.XAxis.TickLength = [0,0];
curr_ax.YAxis.TickLength = [0,0];
curr_ax.ZAxis.Visible= 'off';
fig{imType}.InvertHardcopy = 'off';drawnow
end
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/importPublicRes.m | .m | 3,994 | 109 | function public = importPublicRes(filename, startRow, endRow)
%IMPORTFILE Import numeric data from a text file as a matrix.
% PUBLIC = IMPORTFILE(FILENAME) Reads data from text file FILENAME for
% the default selection.
%
% PUBLIC = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows
% STARTROW through ENDROW of text file FILENAME.
%
% Example:
% public = importfile('public.csv', 1, 5);
%
% See also TEXTSCAN.
% Auto-generated by MATLAB on 2017/09/26 20:03:12
%% Initialize variables.
delimiter = ',';
if nargin<=2
startRow = 1;
endRow = inf;
end
%% Read columns of data as strings:
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%*s%s%s%*s%*s%*s%s%s%s%*s%s%*s%s%s%s%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
for block=2:length(startRow)
frewind(fileID);
dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter, 'HeaderLines', startRow(block)-1, 'ReturnOnError', false);
for col=1:length(dataArray)
dataArray{col} = [dataArray{col};dataArrayBlock{col}];
end
end
%% Close the text file.
fclose(fileID);
%% Convert the contents of columns containing numeric strings to numbers.
% Replace non-numeric strings with NaN.
raw = repmat({''},length(dataArray{1}),length(dataArray)-1);
for col=1:length(dataArray)-1
raw(1:length(dataArray{col}),col) = dataArray{col};
end
numericData = NaN(size(dataArray{1},1),size(dataArray,2));
for col=[4,5,6,7,8,9,10]
% Converts strings in the input cell array to numbers. Replaced non-numeric
% strings with NaN.
rawData = dataArray{col};
for row=1:size(rawData, 1);
% Create a regular expression to detect and remove non-numeric prefixes and
% suffixes.
regexstr = '(?<prefix>.*?)(?<numbers>([-]*(\d+[\,]*)+[\.]{0,1}\d*[eEdD]{0,1}[-+]*\d*[i]{0,1})|([-]*(\d+[\,]*)*[\.]{1,1}\d+[eEdD]{0,1}[-+]*\d*[i]{0,1}))(?<suffix>.*)';
try
result = regexp(rawData{row}, regexstr, 'names');
numbers = result.numbers;
% Detected commas in non-thousand locations.
invalidThousandsSeparator = false;
if any(numbers==',');
thousandsRegExp = '^\d+?(\,\d{3})*\.{0,1}\d*$';
if isempty(regexp(numbers, thousandsRegExp, 'once'));
numbers = NaN;
invalidThousandsSeparator = true;
end
end
% Convert numeric strings to numbers.
if ~invalidThousandsSeparator;
numbers = textscan(strrep(numbers, ',', ''), '%f');
numericData(row, col) = numbers{1};
raw{row, col} = numbers{1};
end
catch me
end
end
end
%% Split data into numeric and cell columns.
rawNumericColumns = raw(:, [4,5,6,7,8,9,10]);
rawCellColumns = raw(:, [1,2,3]);
%% Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),rawNumericColumns); % Find non-numeric cells
rawNumericColumns(R) = {NaN}; % Replace non-numeric cells
%% Create output variable
public = table;
public.Dataset = rawCellColumns(:, 1);
public.Modality = rawCellColumns(:, 2);
public.Wobble = rawCellColumns(:, 3);
public.ThresPhoton = cell2mat(rawNumericColumns(:, 1));
public.TP = cell2mat(rawNumericColumns(:, 2));
public.FP = cell2mat(rawNumericColumns(:, 3));
public.Jaccard = cell2mat(rawNumericColumns(:, 4));
public.Recall = cell2mat(rawNumericColumns(:, 5));
public.Precision = cell2mat(rawNumericColumns(:, 6));
public.RMSExyz = cell2mat(rawNumericColumns(:, 7));
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_TVSTORM.m | .m | 6,513 | 173 | %% FILE STANDARDISATION : TVSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'TVSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 0;%same but for beads file
unit = 1;%ratio current_unit to nm : conversion to nm from current unit
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz])*unit;
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz])*unit;
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_3DWTM.m | .m | 6,813 | 178 | %% FILE STANDARDISATION : 3D-WTM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = '3D-WTM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_CEL0.m | .m | 7,017 | 182 | %% FILE STANDARDISATION : CEL0
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'CEL0';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 4;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_FIRESTORM.m | .m | 6,821 | 178 | %% FILE STANDARDISATION : FIRESTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'FIRESTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 3;%ind frame,2
param.indx = 1;%ind x nm
param.indy = 2;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 4;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = -50;%value of pixel x shifting, nm
y_shift_nm = -50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_localizer.m | .m | 6,825 | 178 | %% FILE STANDARDISATION : localizer
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'localizer';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 4;%ind x nm
param.indy = 5;%ind y nm
param.indz = [0,6];%ind z nm, set 0 if unavailable
param.indint = 2;%ind intensity (photons). If not available, put [],8
header = 5;%# header lines
header_beads = 1;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = false;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_ThunderSTORM.m | .m | 6,533 | 173 | %% FILE STANDARDISATION : ThunderSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'ThunderSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = [10,5];%ind z nm, set 0 if unavailable
param.indint = [6,10];%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio current_unit to nm : conversion to nm from current unit
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz])*unit;
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz])*unit;
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_HeaHD_deprecated.m | .m | 4,617 | 134 | %% FILE STANDARDISATION NO BEADS : HeaHD
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'HeaHD';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 0;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
csvwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_ALOHA.m | .m | 4,633 | 134 | %% FILE STANDARDISATION NO BEADS : ALOHA
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'ALOHA';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
unit = 100;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_QCSTORMbeads.m | .m | 7,023 | 182 | %% FILE STANDARDISATION : QC-STORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'QC-STORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 10;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 7;%ind intensity (photons). If not available, put 0
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_WaveTracer_old.m | .m | 4,460 | 130 | %% FILE STANDARDISATION NO BEADS : WaveTracer
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'WaveTracer';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 2;%ind intensity (photons). If not available, put [],8
header = 1;%has header or not
unit = 1000;%ratio current_unit to nm : conversion to nm from current unit
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz])*unit;
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
csvwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_Brecs.m | .m | 4,634 | 134 | %% FILE STANDARDISATION NO BEADS : Brecs
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'Brecs';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2), loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name, filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep, test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_L1H.m | .m | 4,441 | 129 | %% FILE STANDARDISATION NO BEADS : L1H
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%has header or not
unit = 1;%ratio current_unit to nm : conversion to nm from current unit
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = -50;%value of pixel x shifting, nm
y_shift_nm = -50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
participant_name = 'L1H';%participant name
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz])*unit;
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title('Software Localizations');
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_MIATool.m | .m | 6,817 | 178 | %% FILE STANDARDISATION : MiaTool-RMS
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'MIATool';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_QCSTORM.m | .m | 4,635 | 134 | %% FILE STANDARDISATION NO BEADS : QC-STORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'QC-STORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 10;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 7;%ind intensity (photons). If not available, put 0
header = 1;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_MIAToolJAC.m | .m | 6,821 | 178 | %% FILE STANDARDISATION : MiaTool-RMS
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'MIATool-JAC';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_GT.m | .m | 6,807 | 178 | %% FILE STANDARDISATION : GT
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'GT';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 0;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_STORMChaser.m | .m | 8,249 | 224 | %% FILE STANDARDISATION : STORMChaser
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
%%% Special convert here because intensity column available in one file %%%
clear
participant_name = 'STORMChaser';%participant name
% user related parameters
param.sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put 0
param.checkInt = 1;%Will check if there is an intensity column at param.indint
header = 1;%# header lines
header_beads = 0;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%fprintf('this file\n')
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
sep = param.sep;
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
indint_bead = indint;
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
if param.checkInt
try
loc(:,param.indint);
catch ME
indint = 0;
fprintf('localisation file has no intensity\n');
end
try
loc_beads(:,param.indint);
catch ME
indint_bead = 0;
fprintf('bead localisation file has no intensity\n');
end
end
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if param.checkInt
try
loc(:,param.indint);
catch ME
indint = 0;
fprintf('localisation file has no intensity\n');
end
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if param.checkInt
try
loc_beads(:,param.indint);
catch ME
indint_bead = 0;
fprintf('bead localisation file has no intensity\n');
end
end
if indz==0
if indint_bead==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint_bead])),2) > 0;
end
elseif indint_bead==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint_bead])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
if indint_bead==0
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint_bead = size(loc_beads,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_localizer_SS.m | .m | 6,831 | 178 | %% FILE STANDARDISATION : localizer_SS
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'localizer_SS';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 4;%ind x nm
param.indy = 5;%ind y nm
param.indz = [0,6];%ind z nm, set 0 if unavailable
param.indint = 2;%ind intensity (photons). If not available, put [],8
header = 5;%# header lines
header_beads = 1;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = false;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_SMAP.m | .m | 7,017 | 182 | %% FILE STANDARDISATION : SMAP
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SMAP';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_localizer_GLRT.m | .m | 6,835 | 178 | %% FILE STANDARDISATION : localizer_GLRT
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'localizer_GLRT';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 4;%ind x nm
param.indy = 5;%ind y nm
param.indz = [0,6];%ind z nm, set 0 if unavailable
param.indint = 2;%ind intensity (photons). If not available, put [],8
header = 5;%# header lines
header_beads = 1;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = false;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_Octane.m | .m | 6,815 | 178 | %% FILE STANDARDISATION : Octane
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'Octane';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 4;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
header_beads = 0;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_PeakFit_MLEC.m | .m | 6,828 | 178 | %% FILE STANDARDISATION : PeakFit_MLEC
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'PeakFit_MLEC';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 10;%ind x nm
param.indy = 11;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 8;%ind intensity (photons). If not available, put [],8
header = 8;%# header lines
header_beads = 8;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_BaselineLocalization.m | .m | 6,843 | 178 | %% FILE STANDARDISATION : BaselineLocalization
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'BaselineLocalization';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_QuickPALM.m | .m | 6,821 | 178 | %% FILE STANDARDISATION : QuickPALM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'QuickPALM';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 15;%ind frame,2
param.indx = 5;%ind x nm
param.indy = 6;%ind y nm
param.indz = 7;%ind z nm, set 0 if unavailable
param.indint = 2;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_MIAToolRMS.m | .m | 6,821 | 178 | %% FILE STANDARDISATION : MiaTool-RMS
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'MIATool-RMS';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_RainSTORM.m | .m | 6,825 | 178 | %% FILE STANDARDISATION : RainSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'RainSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = [0,4];%ind z nm, set 0 if unavailable
param.indint = [4,5];%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_3DSTORMTools.m | .m | 6,825 | 178 | %% FILE STANDARDISATION : 3D-STORM-Tools
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = '3D-STORM-Tools';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_WTM.m | .m | 6,463 | 173 | %% FILE STANDARDISATION : WTM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'WTM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 8;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%has header or not
unit = 100;%ratio current_unit to nm : conversion to nm from current unit
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz])*unit;
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz])*unit;
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_PeakFit_LSE.m | .m | 6,826 | 178 | %% FILE STANDARDISATION : PeakFit_LSE
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'PeakFit_LSE';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 10;%ind x nm
param.indy = 11;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 8;%ind intensity (photons). If not available, put [],8
header = 8;%# header lines
header_beads = 8;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_RapidSTORM.m | .m | 6,834 | 178 | %% FILE STANDARDISATION : RapidSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'RapidSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = [5,6];%ind frame,2
param.indx = 1;%ind x nm
param.indy = 3;%ind y nm
param.indz = [0,5];%ind z nm, set 0 if unavailable
param.indint = [6,7];%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = false;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end),zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
%addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_mlePALM.m | .m | 7,028 | 182 | %% FILE STANDARDISATION : mlePALM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'mlePALM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = [0,4];%ind z nm, set 0 if unavailable
param.indint = [4,5];%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
%addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_easyDH.m | .m | 6,812 | 179 | %% FILE STANDARDISATION : EasyDH
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'EasyDH';%participant name
% user related parameters
sep = [];%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 9;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'___*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
%addpath([participant_name,filesep,'standard']);
close all
figure;
scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_SMfit.m | .m | 7,016 | 182 | %% FILE STANDARDISATION : SMfit
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SMfit';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 0;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
%addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_model_no_beads.m | .m | 4,653 | 134 | %% FILE STANDARDISATION NO BEADS : INSERT_PARTICIPANT_NAME
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SMAP';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = [0,4];%ind z nm, set 0 if unavailable
param.indint = [4,5];%ind intensity (photons). If not available, put 0
header = 1;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_RANDOM.m | .m | 6,813 | 178 | %% FILE STANDARDISATION : RANDOM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'RANDOM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
header_beads = 0;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_SOLAR_STORM.m | .m | 6,602 | 173 | %% FILE STANDARDISATION : SOLAR_STORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SOLAR_STORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
header_beads = 0;%same but for beads file
unit = [1,1,1];%ratio for conversion from current unit to nm, or vector 3 x 1 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),1);
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),1);
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_3DDAOSTORM.m | .m | 6,824 | 179 | %% FILE STANDARDISATION : 3D-DAOSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = '3D-DAOSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = -50;%value of pixel x shifting, nm
y_shift_nm = -50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_FALCON.m | .m | 4,650 | 134 | %% FILE STANDARDISATION NO BEADS : INSERT_PARTICIPANT_NAME
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'FALCON';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_CSpline.m | .m | 4,462 | 129 | %% FILE STANDARDISATION NO BEADS : CSpline
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%has header or not
unit = 1;%ratio current_unit to nm : conversion to nm from current unit
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = -50;%value of pixel x shifting, nm
y_shift_nm = -50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
participant_name = 'CSpline';%participant name
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz])*unit;
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations -',modality]);
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_NeuralSTORM.m | .m | 4,640 | 134 | %% FILE STANDARDISATION NO BEADS : NeuralSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'NeuralSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 2;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 0;%ind intensity (photons). If not available, put 0
header = 0;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_WaveTracer.m | .m | 7,030 | 182 | %% FILE STANDARDISATION : WaveTracer
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'WaveTracer';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 2;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1000;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_MiaLang.m | .m | 6,815 | 178 | %% FILE STANDARDISATION : MiaLang
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'MiaLang';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 5;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 4;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_model.m | .m | 7,060 | 182 | %% FILE STANDARDISATION : INSERT_PARTICIPANT_NAME
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'INSERT_PARTICIPANT_NAME';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = [0,4];%ind z nm, set 0 if unavailable
param.indint = [4,5];%ind intensity (photons). If not available, put 0
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_ADCG.m | .m | 6,805 | 178 | %% FILE STANDARDISATION : ADCG
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'ADCG';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
header_beads = 0;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_PeakSelector.m | .m | 6,830 | 178 | %% FILE STANDARDISATION : PeakSelector
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'PeakSelector';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 10;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 7;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 100/133;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_PhasorThunderSTORM.m | .m | 7,044 | 182 | %% FILE STANDARDISATION : Phasor-ThunderSTORM
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'Phasor-ThunderSTORM';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 0;%ind intensity (photons). If not available, put 0
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ', 1, nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
elseif indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indz indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/old_convert_SMAP.m | .m | 4,629 | 134 | %% FILE STANDARDISATION NO BEADS : SMAP
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SMAP';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_EasyDHPSF.m | .m | 6,818 | 178 | %% FILE STANDARDISATION : EasyDHPSF
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'EasyDHPSF';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 4;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
header_beads = 1;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [1280, 1280, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'____*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_SFP_Estimator.m | .m | 6,828 | 178 | %% FILE STANDARDISATION : SFP_Estimator
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SFP_Estimator';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 4;%ind frame,2
param.indx = 1;%ind x nm
param.indy = 2;%ind y nm
param.indz = 3;%ind z nm, set 0 if unavailable
param.indint = 5;%ind intensity (photons). If not available, put [],8
header = 0;%# header lines
header_beads = 0;%same but for beads file
unit = 1;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 50;%value of pixel x shifting, nm
y_shift_nm = 50;%value of pixel y shifting, nm
frameIsOneIndexed = false;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_PeakFit_MLE.m | .m | 6,826 | 178 | %% FILE STANDARDISATION : PeakFit_MLE
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'PeakFit_MLE';%participant name
% user related parameters
sep = ' ';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 1;%ind frame,2
param.indx = 10;%ind x nm
param.indy = 11;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 8;%ind intensity (photons). If not available, put [],8
header = 8;%# header lines
header_beads = 8;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_SMolPhot.m | .m | 4,504 | 130 | %% FILE STANDARDISATION NO BEADS : SMolPhot
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SMolPhot';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4 - length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_SMAPRMS.m | .m | 4,637 | 134 | %% FILE STANDARDISATION NO BEADS : SMAP-RMS
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'SMAP-RMS';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, others], if 1D => for all
param.indframe = 2;%ind frame,2
param.indx = 3;%ind x nm
param.indy = 4;%ind y nm
param.indz = 5;%ind z nm, set 0 if unavailable
param.indint = 6;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
unit = 1;%ratio : conversion to nm from current unit, can be vector 1 x 3
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) - x_shift_nm;
loc(:,indy) = loc(:,indy) - y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
figure;
scatter(loc(:,2),loc(:,3),1,'filled');title(['Software Localizations-',modality]);drawnow
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
end
addpath([participant_name,filesep,'standard']);
close all | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/converter/convert_PALMER.m | .m | 6,813 | 178 | %% FILE STANDARDISATION : PALMER
% Specific to each participant, standardised output file saved in csv
% format : Dataset Localisation & Beads localisation standard format in
% 'standard' folder
clear
participant_name = 'PALMER';%participant name
% user related parameters
sep = '';%' ';%separator type
%2 elements vector : [2D, 3D], if 1D => for all
param.indframe = 5;%ind frame,2
param.indx = 2;%ind x nm
param.indy = 3;%ind y nm
param.indz = 0;%ind z nm, set 0 if unavailable
param.indint = 4;%ind intensity (photons). If not available, put [],8
header = 1;%# header lines
header_beads = 1;%same but for beads file
unit = 100;%ratio for conversion from current unit to nm, or vector 1x3 for each dimension
%e.g. original unit in camera pixel (100nm) => unit = 100;
%e.g. already in nm => unit = 1;
Yinv = false;%boolean inversed Y axis
x_shift_nm = 0;%value of pixel x shifting, nm
y_shift_nm = 0;%value of pixel y shifting, nm
frameIsOneIndexed = true;%Boolean frame numbering starting at 0 or 1
%data related parameters
%raw_pix_siz = 100;%nm raw pixel size
fov = [6400, 6400, 1500];%nm
fov_beads = [12800, 12800, 1500];%nm
%folders related parameters
upload_path = [participant_name,filesep,'upload'];
if exist([participant_name,filesep,'standard'],'dir')
error('folder standard already exists !');
end
%% Loop over uploaded files
fnames = dir([upload_path,filesep,'MT*']);
fnames = [fnames;dir([upload_path,filesep,'ER*'])];
for k = 1:length(fnames)
test_name = fnames(k).name;
splitPos = strfind(test_name,'____');
modality = test_name(splitPos(1)+4:splitPos(2)-1);
% Data reading
if strcmp(modality,'2D')
indframe = param.indframe(1);
indx = param.indx(1);
indy = param.indy(1);
indz = param.indz(1);
indint = param.indint(1);
else %3D
indframe = param.indframe(end);
indx = param.indx(end);
indy = param.indy(end);
indz = param.indz(end);
indint = param.indint(end);
end
beads_file = dir([upload_path,filesep,'Beads____',modality,'*']);
beads_file = beads_file.name;
try
if isempty(sep)
[~, sep] = importdata([upload_path filesep test_name]);
fprintf('Detected separator : %s\n',sep);
end
loc = dlmread([upload_path filesep test_name], sep, header,0);
Nerrorline = 0;
loc_beads = dlmread([upload_path filesep beads_file],sep,header_beads,0);
catch ME
%dataset localisation
fid = fopen([upload_path filesep test_name]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc = zeros(length(out{1}),nCol);
for m = 1:nCol
loc(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc(:,[indframe indx indy indz indint])),2) > 0;
end
loc(line2rm,:) = [];
Nerrorline = sum(line2rm);
%beads localization
fid = fopen([upload_path filesep beads_file]);
nCol = fgetl(fid);
nCol = length(find(nCol==sep))+1;
out = textscan(fid,repmat('%s ',1,nCol),'delimiter',sep);
fclose(fid);
loc_beads = zeros(length(out{1}),nCol);
for m = 1:nCol
loc_beads(:,m) = str2double(out{m});
end
if indz==0
if indint==0
line2rm = sum(isnan(loc_beads(:,[indframe indx indy])),2) > 0;
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indint])),2) > 0;
end
else
line2rm = sum(isnan(loc_beads(:,[indframe indx indy indz indint])),2) > 0;
end
loc_beads(line2rm,:) = [];
end
% Standardization : comments describe the standard format
% Z-column : add a Z-column if missing
if indz == 0
loc = [loc(:,1:end),zeros(size(loc,1),1)];
loc_beads = [loc_beads(:,1:end), zeros(size(loc_beads,1),1)];
indz = size(loc,2);
end
% Photon-column : add a photon-column if missing
if indint==0
loc = [loc,zeros(size(loc,1),1)];
loc_beads = [loc_beads,zeros(size(loc_beads,1),1)];
indint = size(loc,2);
end
% Unit : conversion to nm
loc(:,[indx,indy,indz]) = loc(:,[indx,indy,indz]).*repmat(unit,size(loc,1),4-length(unit));
loc_beads(:,[indx,indy,indz]) = loc_beads(:,[indx,indy,indz]).*repmat(unit,size(loc_beads,1),4-length(unit));
% Y axis direction : (0,0) at the top left corner, Y axis direction toward bottom
if Yinv
loc(:,indy) = fov(2) - loc(:,indy);
loc_beads(:, indy) = fov_beads(2) - loc_beads(:,indy);
end
% Frame index : starts at 1
loc(:,indframe) = loc(:,indframe) + ~frameIsOneIndexed*1;
loc_beads(:,indframe) = loc_beads(:,indframe) + ~frameIsOneIndexed*1;
% Origin : (0,0) at the top left corner (of the top left pixel)
loc(:,indx) = loc(:,indx) + x_shift_nm;
loc(:,indy) = loc(:,indy) + y_shift_nm;
loc_beads(:,indx) = loc_beads(:,indx) + x_shift_nm;
loc_beads(:,indy) = loc_beads(:,indy) + y_shift_nm;
% Z = 0 at the focal plane
if min(loc(:,indz)) >= 0 && sum(loc(:,indz))~=0
loc(:,indz) = loc(:,indz) - fov(3)/2;
loc_beads(:,indz) = loc_beads(:,indz) - fov_beads(3)/2;
end
loc = loc(:,[indframe indx indy indz indint]);
loc_beads = loc_beads(:,[indframe indx indy indz indint]);
gt_beads = csvread(['Ground_truth',filesep,'Beads',filesep,'activations.csv']);
if exist('dispOrthoView.m','file') %display bead positions in orthoview
dispOrthoView(['Former Orthoview : ',participant_name,' ', modality],loc_beads,gt_beads,5);
end
% Save standardised file in csv format
if ~exist([participant_name,filesep,'standard'],'dir')
mkdir(participant_name,'standard');
end
dlmwrite([participant_name,filesep,'standard',...
filesep,test_name(1:end-4),'____standard____Nerror_',num2str(Nerrorline),...
'____Nfluor_',num2str(size(loc,1)),'____date_',date,'.csv'],loc,'precision',8);
dlmwrite([participant_name,filesep,'standard',filesep,beads_file(1:end-4),'____standard','.csv'],loc_beads,'precision',8);
fprintf('%s %i %i\n',test_name(1:splitPos(1)-1),Nerrorline,size(loc,1));
end
addpath([participant_name,filesep,'standard']);
close all
figure; scatter3(loc_beads(:,2),loc_beads(:,3),loc_beads(:,1),'r');hold on;
scatter3(gt_beads(:,3),gt_beads(:,4),gt_beads(:,1),'g'); | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/colormap/morgenstemning.m | .m | 7,649 | 211 | function cmap=morgenstemning(n,varargin)
%MORGENSTEMNING Colormap that increases linearly in lightness (with colors)
%
% Written by Matthias Geissbuehler - matthias.geissbuehler@a3.epfl.ch
% January 2013
%
% Colormap that increases linearly in lightness (such as a pure black to white
% map) but incorporates additional colors that help to emphasize the
% transitions and hence enhance the perception of the data.
% This colormap is designed to be printer-friendly both for color printers as
% as well as B&W printers.
%
% Credit: The idea of the passages over blue&red stems from ImageJ's LUT 'Fire'
% Our colormap corrects the color-printout-problems as well as the
% non-linearity in the fire-colormap which would make it incompatible
% with a B&W printing.
%
%
% See also: isolum, ametrine
%
%
% Please feel free to use this colormap at your own convenience.
% A citation to the original article is of course appreciated, however not "mandatory" :-)
%
% M. Geissbuehler and T. Lasser
% "How to display data by color schemes compatible with red-green color perception deficiencies
% Optics Express, 2013
%
%
% For more detailed information, please see:
% http://lob.epfl.ch -> Research -> Color maps
%
%
% Usage:
% cmap = morgenstemning(n)
%
% All arguments are optional:
%
% n The number of elements (256)
%
% Further on, the following options can be applied
% 'minColor' The absolute minimum value can have a different color
% ('none'), 'white','black','lightgray', 'darkgray'
% or any RGB value ex: [0 1 0]
% 'maxColor' The absolute maximum value can have a different color
% 'invert' (0), 1=invert the whole colormap
% 'gamma' The gamma of the monitor to be used (1.8)
%
%
% Examples:
% figure; imagesc(peaks(200));
% colormap(morgenstemning)
% colorbar
%
% figure; imagesc(peaks(200));
% colormap(morgenstemning(256,'minColor','black','maxColor',[0 1 0]))
% colorbar
%
% figure; imagesc(peaks(200));
% colormap(morgenstemning(256,'invert',1,'minColor','darkgray'))
% colorbar
%
%
%
%
%
% This colormap is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This colormap is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% Copyright 2013 Matthias Geissbuehler - matthias.geissbuehler@a3.epfl.ch
% $Revision: 3.0 $ $Date: 2013/01/29 12:00:00 $
p=inputParser;
p.addParamValue('minColor','none');
p.addParamValue('maxColor','none');
p.addParamValue('invert',0, @(x)x==0 || x==1);
p.addParamValue('gamma',1.8, @(x)x>0);
if nargin==1
p.addRequired('n', @(x)x>0 && mod(x,1)==0);
p.parse(n);
elseif nargin>1
p.addRequired('n', @(x)x>0 && mod(x,1)==0);
p.parse(n, varargin{:});
else
p.addParamValue('n',256, @(x)x>0 && mod(x,1)==0);
p.parse();
end
config = p.Results;
n=config.n;
%the ControlPoints
cP(:,1) = [0 0 0]./255;
cP(:,2) = [25 53 95]./255; %cyan
cP(:,3) = [192 27 111]./255; %redish-magenta
cP(:,4) = [252 229 0]./255; %yellow
cP(:,5) = [255 255 255]./255;
number_of_elements_reached = false;
last_n = size(cP,2);
curr_n = last_n .* 2 - 1;
last_cmap = double(cP');
% Normalization and smooth interpolation while keeping
% strictly monotonically increasing gray-values:
%
% 1. interpolate 2x the number of points of the previous cmap (controlpoints)
% 2. normalize all of them
% 3. Loop from 1. until number of points is >n
% 4. Interpolate to the correct number of points (n)
while ~number_of_elements_reached;
cmap = abs(interp1((1:last_n),last_cmap,linspace(1,last_n,curr_n),'pchip')); % Interpolation between the control-Points
checkIfAnyAbove1 = 1;
while checkIfAnyAbove1
% Normalization by calculation of the gray-value
% using the average RGB-value (gamma-corrected)
tempgraymap = mean(cmap.^config.gamma,2);
tempgraymap = tempgraymap .^(1/config.gamma);
cmap(:,1)=cmap(:,1)./tempgraymap.*linspace(0,1,curr_n)';
cmap(:,2)=cmap(:,2)./tempgraymap.*linspace(0,1,curr_n)';
cmap(:,3)=cmap(:,3)./tempgraymap.*linspace(0,1,curr_n)';
cmap(isnan(cmap))=0;
cmap = round(10000*cmap)./10000; % staying within reasonable required precision
% check if during normalization any value is now bigger than 1
above1 = cmap>1;
if sum(above1(:))
mydiff = 0.025;
if sum(above1(:,1)) % any R>1 ?
myIndexes = find(above1(:,1));
cmap(myIndexes,1) = (1-mydiff) .* cmap(myIndexes,1); % remove a little bit
cmap(myIndexes,2) = (mydiff/2) .* (1-cmap(myIndexes,2)) + cmap(myIndexes,2); % add a little bit to other values
cmap(myIndexes,3) = (mydiff/2) .* (1-cmap(myIndexes,3)) + cmap(myIndexes,3); % add a little bit to other values
end
if sum(above1(:,2)) % any G>1 ?
myIndexes = find(above1(:,2));
cmap(myIndexes,2) = (1-mydiff) .* cmap(myIndexes,2); % remove a little bit
cmap(myIndexes,1) = (mydiff/2) .* (1-cmap(myIndexes,1)) + cmap(myIndexes,1); % add a little bit to other values
cmap(myIndexes,3) = (mydiff/2) .* (1-cmap(myIndexes,3)) + cmap(myIndexes,3); % add a little bit to other values
end
if sum(above1(:,3)) % any B>1 ?
myIndexes = find(above1(:,3));
cmap(myIndexes,3) = (1-mydiff) .* cmap(myIndexes,3); % remove a little bit
cmap(myIndexes,1) = (mydiff/2) .* (1-cmap(myIndexes,1)) + cmap(myIndexes,1); % add a little bit to other values
cmap(myIndexes,2) = (mydiff/2) .* (1-cmap(myIndexes,2)) + cmap(myIndexes,2); % add a little bit to other values
end
checkIfAnyAbove1 = 1;
else
checkIfAnyAbove1 = 0;
end
end
last_n = curr_n;
curr_n = last_n .* 2 - 1;
last_cmap = cmap;
if last_n > n
number_of_elements_reached = true;
end
end
cmap = abs(interp1((1:last_n),last_cmap,linspace(1,last_n,n)));
% Additional modifications of the colormap
if config.invert
cmap = flipud(cmap);
end
if ischar(config.minColor)
if ~strcmp(config.minColor,'none')
switch config.minColor
case 'white'
cmap(1,:) = [1 1 1];
case 'black'
cmap(1,:) = [0 0 0];
case 'lightgray'
cmap(1,:) = [0.8 0.8 0.8];
case 'darkgray'
cmap(1,:) = [0.2 0.2 0.2];
end
end
else
cmap(1,:) = config.minColor;
end
if ischar(config.maxColor)
if ~strcmp(config.maxColor,'none')
switch config.maxColor
case 'white'
cmap(end,:) = [1 1 1];
case 'black'
cmap(end,:) = [0 0 0];
case 'lightgray'
cmap(end,:) = [0.8 0.8 0.8];
case 'darkgray'
cmap(end,:) = [0.2 0.2 0.2];
end
end
else
cmap(end,:) = config.maxColor;
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/colormap/isolum.m | .m | 6,441 | 175 | function cmap=isolum(n,varargin)
%ISOLUM Isoluminant-Colormap compatible with red-green color perception deficiencies
%
% Written by Matthias Geissbuehler - matthias.geissbuehler@a3.epfl.ch
% January 2013
%
% Features:
% 1) All colors have the same luminescence (ideal for lifetime
% images that will be displayed with an additional transparency map
% to "mask" places where the lifetime is not well defined)
% 2) Color vision deficient persons can only see reduced color: as much
% as 10% of adult male persons have a red-green defiency (either
% Deuteranope or Protanope) -> as a result they can only distinguish
% between blue and yellow. A colormap which is "save" for color vision
% deficient persons is hence only based on these colors.
% However: people with normal vision DO have a larger space of colors
% available: it would be a pity to discard this freedom. So the goal
% must be a colormap that is both using as many colors as possible
% for normal-sighted people as well as a colormap that will "look"
% blue-yellow to people with colorblindness without transitions that
% falsify the information by including a non-distinct transitions
% (as is the case for many colormaps based on the whole spectrum
% (ex. rainbow or jet).
% That's what this colormap here tries to achieve.
% 3) In order to be save for publications, the colormap uses colors that
% are only from the CMYK colorspace (or at least not too far)
%
%
% See also: ametrine, morgenstemning
%
%
% Please feel free to use this colormap at your own convenience.
% A citation to the original article is of course appreciated, however not "mandatory" :-)
%
% M. Geissbuehler and T. Lasser
% "How to display data by color schemes compatible with red-green color perception deficiencies
% Optics Express, 2013
%
%
% For more detailed information, please see:
% http://lob.epfl.ch -> Research -> Color maps
%
%
% Usage:
% cmap = isolum(n)
%
% All arguments are optional:
%
% n The number of elements (256)
%
% Further on, the following options can be applied
% 'gamma' The gamma of the monitor to be used (1.8)
% 'minColor' The absolute minimum value can have a different color
% ('none'), 'white','black','lightgray', 'darkgray'
% or any RGB value ex: [0 1 0]
% 'maxColor' The absolute maximum value can have a different color
% 'invert' (0), 1=invert the whole colormap
%
% Examples:
% figure; imagesc(peaks(200));
% colormap(isolum)
% colorbar
%
% figure; imagesc(peaks(200));
% colormap(isolum(256,'gamma',1.8,'minColor','black','maxColor',[0 1 0]))
% colorbar
%
% figure; imagesc(peaks(200));
% colormap(isolum(256,'invert',1,'minColor','white'))
% colorbar
%
%
%
%
%
%
% This colormap is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This colormap is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% Copyright 2013 Matthias Geissbuehler - matthias.geissbuehler@a3.epfl.ch
% $Revision: 3.0 $ $Date: 2013/01/29 12:00:00 $
p=inputParser;
p.addParamValue('gamma',1.8, @(x)x>0);
p.addParamValue('minColor','none');
p.addParamValue('maxColor','none');
p.addParamValue('invert',0, @(x)x==0 || x==1);
if nargin==1
p.addRequired('n', @(x)x>0 && mod(x,1)==0);
p.parse(n);
elseif nargin>1
p.addRequired('n', @(x)x>0 && mod(x,1)==0);
p.parse(n, varargin{:});
else
p.addParamValue('n',256, @(x)x>0 && mod(x,1)==0);
p.parse();
end
config = p.Results;
n=config.n;
%the ControlPoints and the spacing between them
%the ControlPoints in a very isoluminescence case
cP(:,1) = [90 190 245]./255; k(1)=1; %cyan at index 1
cP(:,2) = [157 157 200]./255; k(2)=16; %purple at index 16
cP(:,3) = [220 150 130]./255; k(3)=32; %purple at index 32
cP(:,4) = [245 120 80 ]./255; k(4)=43; %redish at index 43
cP(:,5) = [180 180 0 ]./255; k(5)=64; %yellow at index 64
% Making them strictly isoluminescent
tempgraymap = mean((cP).^config.gamma,1);
tempgraymap = tempgraymap .^(1/config.gamma);
cP(1,:)=cP(1,:)./tempgraymap.*mean(tempgraymap);
cP(2,:)=cP(2,:)./tempgraymap.*mean(tempgraymap);
cP(3,:)=cP(3,:)./tempgraymap.*mean(tempgraymap);
for i=1:4 % interpolation between control points, while keeping the luminescence constant
f{i} = linspace(0,1,(k(i+1)-k(i)+1))'; % linear space between these controlpoints
ind{i} = linspace(k(i),k(i+1),(k(i+1)-k(i)+1))';
cmap(ind{i},1) = ((1-f{i})*cP(1,i)^config.gamma + f{i}*cP(1,i+1)^config.gamma).^(1/config.gamma);
cmap(ind{i},2) = ((1-f{i})*cP(2,i)^config.gamma + f{i}*cP(2,i+1)^config.gamma).^(1/config.gamma);
cmap(ind{i},3) = ((1-f{i})*cP(3,i)^config.gamma + f{i}*cP(3,i+1)^config.gamma).^(1/config.gamma);
end
% normal linear interpolation to achieve the required number of points for the colormap
cmap = abs(interp1(linspace(0,1,size(cmap,1)),cmap,linspace(0,1,n)));
if config.invert
cmap = flipud(cmap);
end
if ischar(config.minColor)
if ~strcmp(config.minColor,'none')
switch config.minColor
case 'white'
cmap(1,:) = [1 1 1];
case 'black'
cmap(1,:) = [0 0 0];
case 'lightgray'
cmap(1,:) = [0.8 0.8 0.8];
case 'darkgray'
cmap(1,:) = [0.2 0.2 0.2];
end
end
else
cmap(1,:) = config.minColor;
end
if ischar(config.maxColor)
if ~strcmp(config.maxColor,'none')
switch config.maxColor
case 'white'
cmap(end,:) = [1 1 1];
case 'black'
cmap(end,:) = [0 0 0];
case 'lightgray'
cmap(end,:) = [0.8 0.8 0.8];
case 'darkgray'
cmap(end,:) = [0.2 0.2 0.2];
end
end
else
cmap(end,:) = config.maxColor;
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/colormap/ametrine.m | .m | 6,033 | 167 | function cmap=ametrine(n,varargin)
%AMETRINE "Nearly" isoluminant-Colormap compatible with red-green color perception deficiencies
%
% Written by Matthias Geissbuehler - matthias.geissbuehler@a3.epfl.ch
% January 2013
%
% Features:
% 1) All colors have the same luminescence (ideal for lifetime
% images that will be displayed with an additional transparency map
% to "mask" places where the lifetime is not well defined)
% 2) Color vision deficient persons can only see reduced color: as much
% as 10% of adult male persons have a red-green defiency (either
% Deuteranope or Protanope) -> as a result they can only distinguish
% between blue and yellow. A colormap which is "save" for color vision
% deficient persons is hence only based on these colors.
% However: people with normal vision DO have a larger space of colors
% available: it would be a pity to discard this freedom. So the goal
% must be a colormap that is both using as many colors as possible
% for normal-sighted people as well as a colormap that will "look"
% blue-yellow to people with colorblindness without transitions that
% falsify the information by including a non-distinct transitions
% (as is the case for many colormaps based on the whole spectrum
% (ex. rainbow or jet).
% That's what this colormap here tries to achieve.
% 3) In order to be save for publications, the colormap uses colors that
% are only from the CMYK colorspace (or at least not too far)
% 4) In comparison to "isolum", this colormap slightly trades off
% isoluminescence for a higher color contrast
%
%
% See also: isolum, morgenstemning
%
%
% Please feel free to use this colormap at your own convenience.
% A citation to the original article is of course appreciated, however not "mandatory" :-)
%
% M. Geissbuehler and T. Lasser
% "How to display data by color schemes compatible with red-green color perception deficiencies
% Optics Express, 2013
%
%
% For more detailed information, please see:
% http://lob.epfl.ch -> Research -> Color maps
%
%
% Usage:
% cmap = ametrine(n)
%
% All arguments are optional:
%
% n The number of elements (256)
%
% Further on, the following options can be applied
% 'gamma' The gamma of the monitor to be used (1.8)
% 'minColor' The absolute minimum value can have a different color
% ('none'), 'white','black','lightgray', 'darkgray'
% or any RGB value ex: [0 1 0]
% 'maxColor' The absolute maximum value can have a different color
% 'invert' (0), 1=invert the whole colormap
%
% Examples:
% figure; imagesc(peaks(200));
% colormap(ametrine)
% colorbar
%
% figure; imagesc(peaks(200));
% colormap(ametrine(256,'gamma',1.8,'minColor','black','maxColor',[0 1 0]))
% colorbar
%
% figure; imagesc(peaks(200));
% colormap(ametrine(256,'invert',1,'minColor','white'))
% colorbar
%
%
%
%
%
%
% This colormap is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This colormap is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% Copyright 2013 Matthias Geissbuehler - matthias.geissbuehler@a3.epfl.ch
% $Revision: 3.0 $ $Date: 2013/01/29 12:00:00 $
p=inputParser;
p.addParamValue('gamma',1.8, @(x)x>0);
p.addParamValue('minColor','none');
p.addParamValue('maxColor','none');
p.addParamValue('invert',0, @(x)x==0 || x==1);
if nargin==1
p.addRequired('n', @(x)x>0 && mod(x,1)==0);
p.parse(n);
elseif nargin>1
p.addRequired('n', @(x)x>0 && mod(x,1)==0);
p.parse(n, varargin{:});
else
p.addParamValue('n',256, @(x)x>0 && mod(x,1)==0);
p.parse();
end
config = p.Results;
n=config.n;
%the ControlPoints and the spacing between them
%the ControlPoints in a bit more colorful variant -> slightly less
%isoluminescence, but gives a more vivid look
cP(:,1) = [30 60 150]./255; k(1)=1; %cyan at index 1
cP(:,2) = [180 90 155]./255; k(3)=17; %purple at index 17
cP(:,3) = [230 85 65 ]./255; k(4)=32; %redish at index 32
cP(:,4) = [220 220 0 ]./255; k(5)=64; %yellow at index 64
for i=1:3
f{i} = linspace(0,1,(k(i+1)-k(i)+1))'; % linear space between these controlpoints
ind{i} = linspace(k(i),k(i+1),(k(i+1)-k(i)+1))';
end
cmap = interp1((1:4),cP',linspace(1,4,64)); % for non-iso points, a normal interpolation gives better results
% normal linear interpolation to achieve the required number of points for the colormap
cmap = abs(interp1(linspace(0,1,size(cmap,1)),cmap,linspace(0,1,n)));
if config.invert
cmap = flipud(cmap);
end
if ischar(config.minColor)
if ~strcmp(config.minColor,'none')
switch config.minColor
case 'white'
cmap(1,:) = [1 1 1];
case 'black'
cmap(1,:) = [0 0 0];
case 'lightgray'
cmap(1,:) = [0.8 0.8 0.8];
case 'darkgray'
cmap(1,:) = [0.2 0.2 0.2];
end
end
else
cmap(1,:) = config.minColor;
end
if ischar(config.maxColor)
if ~strcmp(config.maxColor,'none')
switch config.maxColor
case 'white'
cmap(end,:) = [1 1 1];
case 'black'
cmap(end,:) = [0 0 0];
case 'lightgray'
cmap(end,:) = [0.8 0.8 0.8];
case 'darkgray'
cmap(end,:) = [0.2 0.2 0.2];
end
end
else
cmap(end,:) = config.maxColor;
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/finddriftfeature.m | .m | 9,491 | 343 | function [drift,driftinfo]=finddriftfeature(pos,par)
global SMAP_stopnow
%pos.xnm .ynm .frame
%frame starts with 1, ascending order, maybe not necessary?
% XXX locData: sort function, general
% parameters and typical values (please adopt)
% par.drift_pixrec=15; %pixelsize of reconstructed images in nm
% par.drift_window=11; %size of region in pixels which gets fittd to determine
% displacement
% par.drift_timepoints=10; %number of time points evaluated
% par.drift_maxdrift=500; %maximal drift in nm (not crucial, rather choose to
% high
%par.drift_maxpix maximum size of recontsructed image
%other functions needed:
%myhist2
%my2DGaussfit
%copyright: Jonas Ries, EMBL, jonas.ries@embl.de
if isfield(par,'repetitionname')
rn=par.repetitionname;
else
rn='';
end
results_ax1=initaxis(par.resultstabgroup,['CC' rn]);
results_ax3=initaxis(par.resultstabgroup,['normalized CC' rn]);
%here: rather from par, from channel range. Make sure it does not get
%displaced. Fill in outside.
lastframe=round(par.framestop);
firstframe=round(par.framestart);
numframes=lastframe-firstframe+1;
%% calculate movie and FFT of movie
pixrec=par.drift_pixrec; %in nm
window=ceil((par.drift_window-1)/2);
timepoints=par.drift_timepoints; %how many timepoints
maxdrift=par.drift_maxdrift; %in nanometers
mx=[min(pos.xnm) max(pos.xnm)]; %ROI which is used for drift correction.
my=[min(pos.ynm) max(pos.ynm)]; %You can put your own routine here
srec(1)=round((mx(2)-mx(1))/pixrec);
srec(2)=round((my(2)-my(1))/pixrec);
if max(srec)>par.drift_maxpixels %too large for reconstruction, fold back
pos.xnm=pos.xnm-min(pos.xnm);pos.ynm=pos.ynm-min(pos.xnm);
maxnm=par.drift_maxpixels*par.drift_pixrec;
pos.xnm=mod(pos.xnm,maxnm);pos.ynm=mod(pos.ynm,maxnm);
mx=[min(pos.xnm) max(pos.xnm)]; %ROI which is used for drift correction.
my=[min(pos.ynm) max(pos.ynm)]; %You can put your own routine here
srec(1)=round((mx(2)-mx(1))/pixrec);
srec(2)=round((my(2)-my(1))/pixrec);
end
% srim= histrender(posr,mx, my, pixrec, pixrec);
nfftexp=2^ceil(log2(max(max(srec),256))); %for fft use power of 2
if nfftexp>2500
nfftexp=round(max(srec(1:2))/2)*2;
end
noff=nfftexp/2+1;
disp('make movie')
Fmovier=makemovie; %calculate fourier transforms of reconstructed images
disp('find displacement')
[ddx, ddy,errx,erry]= finddisplacements2; %determine displacements
ddx=ddx*pixrec; %convert displacements into nm
ddy=ddy*pixrec;
%% bin displacements
[dx,sdxc]=bindisplacementfit(ddx,errx); %determine displacement for each time point
[dy,sdyc]=bindisplacementfit(ddy,erry);
% dx0h=[0; dx];
% dy0h=[0; dy];
s=size(ddx);
% ddxplot=cumsum(diff(ddx));
% ddyplot=cumsum(diff(ddy));
ddxplot=ddx;
ddyplot=ddy;
for kn=1:s(1)
ddxplot(:,kn)=ddx(:,kn)-ddx(kn,kn)+dx(kn);
ddyplot(:,kn)=ddy(:,kn)-ddy(kn,kn)+dy(kn);
end
%interpolate displacemnt for all frames
cfit1=(0:length(dx)-1)*binframes+binframes/2+firstframe; %positions of time points
ctrue=(1:par.maxframeall)'; %positions of frames
if length(dx)>9
[~,sdx,inlier,outlier]=robustMean(ddxplot,2,15);%std for each time point, used for interpolation
[~,sdy]=robustMean(ddyplot,2,15);
sdxm=robustMean(sdx)/2;
sdx(sdx<sdxm)=sdxm;
sdym=robustMean(sdy)/2;
sdy(sdy<sdym)=sdym;
sdxm=robustMean(sdx);
sdym=robustMean(sdy);
% indgx=sdx<5*sdxm;
% indgy=sdy<5*sdym;
end
if length(dx)<=9
sdx=std(ddxplot,0,2); %std for each time point, used for interpolation
sdy=std(ddyplot,1,2);
% indgx=true(size(dx));
% indgy=true(size(dy));
end
indgx=true(size(dx));
indgy=true(size(dy));
% sdx(sdx>5*sdxm)=inf;
% sdy(sdy>5*sdym)=inf;
wx=1./sdx.^2;
wy=1./sdy.^2;
%add to weights
% wx=wx+0.0*mean(wx);
% wy=wy+0.0*mean(wy);
% wx(end)=wx(end)/4;
% wy(end)=wy(end)/4;
% h=cfit1(2)-cfit1(1)
% pset=1/(1+h^3/6)
%give higher weight to first data point:
% wx(1)=wx(1)*2;
% wy(1)=wy(1)*2;
h=cfit1(2)-cfit1(1);
if ~isempty(par.smoothpar)
pset=1/(1+h^3/60*par.smoothpar);
else
pset=[];
end
switch par.smoothmode.Value
case 1 % smoothing spline
[dxt,px] = csaps(double(cfit1(indgx)),double(dx(indgx)),double(pset),double(ctrue),wx(indgx)) ;
[dyt,py] = csaps(double(cfit1(indgy)),double(dy(indgy)),double(pset),double(ctrue),wy(indgy)) ;
case 2
dxt = interp1(double(cfit1(indgx)),double(dx(indgx)),double(ctrue)) ;
dyt = interp1(double(cfit1(indgy)),double(dy(indgy)),double(ctrue)) ;
end
framesall=(1:par.maxframeall);%-firstframe+1;
binend=floor(1*binframes/2);
% dxtt=zeros((par.maxframeall),1);dytt=dxtt;
dxtt=dxt;
dxtt(1:firstframe-1+binframes/2)=dxtt(firstframe-1+binframes/2+1);
% dxtt(firstframe:lastframe)=dxt;
dxtt(lastframe+1-binend:end)=dxtt(lastframe+1-binend);
dytt=dyt;
dytt(1:firstframe-1+binframes/2)=dytt(firstframe-1+binframes/2+1);
% dytt(firstframe:lastframe)=dyt;
dytt(lastframe+1-binend:end)=dytt(lastframe+1-binend);
results_ax2=initaxis(par.resultstabgroup,['dxy/frame' rn]);
subplot(1,2,1)
hold off
plot(ddxplot)
hold on
plot(dx,'k','LineWidth',1.5);
plot(sdx,'k:')
sx=(max(dx)-min(dx));
ylim([min(dx)-sx/2 max(dx)+sx/2])
axis tight
subplot(1,2,2)
hold off
plot(ddyplot)
hold on
plot(dy,'k','LineWidth',1.5);
plot(sdy,'k:')
sy=(max(dx)-min(dx));
ylim([min(dy)-sy/2 max(dy)+sy/2])
axis tight
if par.drift_reference
dxtt=dxtt-dx(end-1);
dytt=dytt-dy(end-1);
dx=dx-dx(end-1);
dy=dy-dy(end-1);
end
driftinfo.dx=dx;
driftinfo.dy=dy;
driftinfo.dxplot=ddxplot;
driftinfo.dyplot=ddyplot;
driftinfo.dxt=dxtt;
driftinfo.dyt=dytt;
driftinfo.binframes=cfit1;
%
initaxis(par.resultstabgroup,['dxy/frame final' rn]);
hold off
plot(cfit1,dx,'x',framesall,dxtt,'k')
hold on
plot(cfit1,dy,'o',framesall,dytt,'r')
xlabel('frame')
ylabel('dx, dy (nm)')
drawnow
initaxis(par.resultstabgroup,['dx vs dy' rn]);
hold off
plot(dxtt,dytt,'k')
hold on
plot(dx,dy,'ro')
plot(dx(1),dy(1),'gx')
xlabel('dx')
ylabel('dy')
drawnow
axis equal
drift.x=dxtt;
drift.y=dytt;
% asdafd
% fitposc=adddrift(positions,dxt,dyt); %recalculate positions
function Fmovier=makemovie %calculate fourier transforms of images
% posr.x=pos.xnm;posr.y=pos.ynm;
binframes=2*ceil(numframes/timepoints/2+1);
frameranges=[firstframe:binframes:lastframe lastframe] ;
timepoints=length(frameranges)-1;
Fmovier=zeros(nfftexp,nfftexp,timepoints,'single');
for k=1:timepoints
indframe=pos.frame<frameranges(k+1)&pos.frame>=frameranges(k);
posr.x=pos.xnm(indframe);posr.y=pos.ynm(indframe);
imager=histrender(posr,mx, my, pixrec, pixrec)';
Fmovier(:,:,k)=fft2(imager,nfftexp,nfftexp);
if SMAP_stopnow
error('execution stopped by user');
end
% figure(89)
% imagesc(imager)
% waitforbuttonpress
end
end
function [ddx, ddy,errx,erry]= finddisplacements2 % find displacements
s=size(Fmovier);
dnumframesh =s(3);
ddx=zeros(dnumframesh-1);ddy=zeros(dnumframesh-1);
errx=ddx;
erry=ddy;
% fhold=imagesc(1,'Parent',results_ax1);
timerh=tic;
for k=1:dnumframesh-1
for l=k+1:dnumframesh
cc=Fmovier(:,:,k).*conj(Fmovier(:,:,l));
ccf=fftshift(ifft2(cc));
[mx,my,outim,outimnorm,errx(k,l),erry(k,l)]=findmaximumgauss(real(ccf),window); %maximum by Gaussian fitting
dxh=mx-noff; dyh=my-noff;
ddx(k,l)=dxh; ddy(k,l)=dyh;
ddx(l,k)=-dxh; ddy(l,k)=-dyh;
errx(l,k)=errx(k,l);erry(l,k)=erry(k,l);
if isfield(par,'showresults') && par.showresults && toc(timerh)>0.5
timerh=tic;
fhold=imagesc(outim,'Parent',results_ax1);
imagesc(outimnorm,'Parent',results_ax3)
results_ax3.Title.String=num2str(k/dnumframesh+(l-k)/dnumframesh^2);
results_ax1.Title.String=num2str(k/dnumframesh+(l-k)/dnumframesh^2);
drawnow
if SMAP_stopnow
error('execution stopped by user');
end
end
end
% disp(k/dnumframesh)
end
end
function [x,y,outim,outimnorm,errx,erry]=findmaximumgauss(img,window)
s=size(img);
win=maxdrift/pixrec; %maxdrift
cent=round(max(1,s(1)/2-win):min(s(1)/2+win,s(1)));
imfm=img(cent,cent);
imfm=filter2(ones(5)/5^2,imfm); %filter a little for better maximum search
[inten,ind]=max(imfm(:)); %determine pixel with maximum intensity to center roi for fitting
[mxh,myh]=ind2sub(size(imfm),ind);
mxh=mxh+cent(1)-1;
myh=myh+cent(1)-1;
%now determine maximum
smallframe=double(img(mxh-window:mxh+window,myh-window:myh+window));
[fitout,outim,outimnorm,ci]=my2Dgaussfit(smallframe,[window+1,window+1,inten,min(smallframe(:)),max(2,3/window),max(2,3/window),0],3);
x=mxh-window+fitout(1)-1;y=myh-window+fitout(2)-1;
dc=ci(:,2)-ci(:,1);
errx=dc(1);erry=dc(2);
end
end
function [dx2,sdx2]=bindisplacementfit(ddx,errx)
% sf=size(ddx);
%idea: we measure displacements between every frames (dxik=xi-xk, xi is
%displacement for frame i). Use all xi as fit parameters, fit function
%calculates dxik. Robust fit.
% weights=1./(errx+.1).^2;
%startp
difddx=diff(ddx);
fp0=cumsum(median(difddx,2));
% fp0=zeros(sf(1)-1,1);
options=statset('nlinfit');
options=statset(options,'Robust','on');
[fp,r,J,COVB,mse] = nlinfit(ddx(:),ddx(:),@bindispf,fp0,options);
ci = nlparci(fp,r,'covar',COVB);
dx2=[0; fp];
% dx2=fp;
sx=ci(:,2)-ci(:,1);
sdx2=[mean(sx);sx];
end
function out=bindisp(fp,ddx)
fph=[0; fp];
ddxf=zeros(length(fph));
for k=1:length(fph)
ddxf(k,:)=fph(k)-fph; %calculate difference
end
% out=ddxf(:);
out=ddxf;
end
function out=bindispf(fp,ddx)
out=bindisp(fp);
out=out(:);
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/finddriftfeatureZ.m | .m | 6,455 | 264 | function [drift,driftinfo]=finddriftfeatureZ(pos,par)
global SMAP_stopnow
%pos.xnm .ynm .znm .frame
%frame starts with 1, ascending order, maybe not necessary?
% XXX locData: sort function, general
% parameters and typical values (please adopt)
% par.drift_pixrec=15; %pixelsize of reconstructed images in nm
% par.drift_window=11; %size of region in pixels which gets fittd to determine
% displacement
% par.drift_timepoints=10; %number of time points evaluated
% par.drift_maxdrift=500; %maximal drift in nm (not crucial, rather choose to
% high
%other functions needed:
%myhist2
%my2DGaussfit
%copyright: Jonas Ries, EMBL, jonas.ries@embl.de
% results_ax1=initaxis(par.resultstabgroup,'cross-correlations');
% results_ax3=initaxis(par.resultstabgroup,'normalized cross-correlations');
%here: rather from par, from channel range. Make sure it does not get
%displaced. Fill in outside.
lastframe=round(par.framestop);
firstframe=round(par.framestart);
numframes=lastframe-firstframe+1;
%% calculate movie and FFT of movie
pixrec=par.drift_pixrecz; %in nm
zb=par.zrange(1):pixrec:par.zrange(2);
window=ceil((par.drift_windowz-1)/2);
timepoints=par.drift_timepointsz; %how many timepoints
% maxdrift=par.drift_maxdrift; %in nanometers
mx=[min(pos.xnm) max(pos.xnm)]; %ROI which is used for drift correction.
xb=mx(1):par.slicewidth:mx(2);
% my=[min(pos.ynm) max(pos.ynm)]; %You can put your own routine here
% srec(1)=round((mx(2)-mx(1))/pixrec);
% srec(2)=round((my(2)-my(1))/pixrec);
% srim= histrender(posr,mx, my, pixrec, pixrec);
% nfftexp=2^ceil(log2(max(srec))); %for fft use power of 2
% noff=nfftexp/2+1;
% disp('make movie')
% Fmovier=makemovie; %calculate fourier transforms of reconstructed images
% disp('find displacement')
plotaxis=initaxis(par.resultstabgroup,'CC z');
[ddz,errz]= finddisplacementsZ; %determine displacements
%
% ddx=ddx*pixrec; %convert displacements into nm
% ddy=ddy*pixrec;
%% bin displacements
[dz,sdzc]=bindisplacementfit(ddz,errz); %determine displacement for each time point
% [dy,sdyc]=bindisplacementfit(ddy,erry);
% dx0h=[0; dx];
% dy0h=[0; dy];
s=size(ddz);
% ddxplot=cumsum(diff(ddx));
% ddyplot=cumsum(diff(ddy));
ddzplot=ddz;
% ddyplot=ddy;
for kn=1:s(1)
ddzplot(:,kn)=ddz(:,kn)-ddz(kn,kn)+dz(kn);
% ddyplot(:,kn)=ddy(:,kn)-ddy(kn,kn)+dy(kn);
end
%interpolate displacemnt for all frames
cfit1=(0:length(dz)-1)*binframes+binframes/2+firstframe; %positions of time points
ctrue=(1:par.maxframeall)'; %positions of frames
if 0%length(dz)>9
[~,sdz,inlier,outlier]=robustMean(ddzplot,2,15);%std for each time point, used for interpolation
% [~,sdy]=robustMean(ddyplot,2,15);
sdzm=robustMean(sdz)/2;
sdz(sdz<sdzm)=sdzm;
sdzm=robustMean(sdz);
indgz=sdz<10*sdzm;
% if length(indgz)<9
% indgz=true(size(dz));
% end
else
sdz=std(ddzplot,0,2); %std for each time point, used for interpolation
% indgz=true(size(dz));
end
indgz=true(size(dz));
% sdx(sdx>5*sdxm)=inf;
% sdy(sdy>5*sdym)=inf;
wz=1./sdz.^2;
%add to weights
% wx=wx+0.0*mean(wx);
% wy=wy+0.0*mean(wy);
% wx(end)=wx(end)/4;
% wy(end)=wy(end)/4;
h=cfit1(2)-cfit1(1);
if ~isempty(par.smoothpar)
pset=1/(1+h^3/60*par.smoothpar);
else
pset=[];
end
% pset=1/(1+h^3/24);
%give higher weight to first data point:
% wx(1)=wx(1)*2;
% wy(1)=wy(1)*2;
% pset=[];
switch par.smoothmode.Value
case 1 % smoothing spline
[dzt,pz] = csaps(double(cfit1(indgz)),double(dz(indgz)),double(pset),double(ctrue),wz(indgz)) ;
case 2
dzt = interp1(double(cfit1(indgz)),double(dz(indgz)),double(ctrue)) ;
end
% [dzt,pz] = csaps(double(cfit1(indgz)),double(dz(indgz)),pset,double(ctrue),wz(indgz)) ;
framesall=(1:par.maxframeall);%-firstframe+1;
binend=floor(1*binframes/2);
% dxtt=zeros((par.maxframeall),1);dytt=dxtt;
dztt=dzt;
dztt(1:firstframe-1+binframes/2)=dztt(firstframe-1+binframes/2+1);
% dxtt(firstframe:lastframe)=dxt;
dztt(lastframe+1-binend:end)=dztt(lastframe+1-binend);
results_ax2=initaxis(par.resultstabgroup,'dz/frame');
% subplot(1,2,1)
hold off
plot(ddzplot)
hold on
plot(dz,'k','LineWidth',1.5);
plot(sdz,'k:')
sz=(max(dz)-min(dz));
ylim([min(dz)-sz/2 max(dz)+sz/2])
axis tight
if par.drift_reference
dztt=dztt-dz(end-1);
dz=dz-dz(end-1);
end
driftinfo.dz=dz;
driftinfo.dzplot=ddzplot;
driftinfo.dzt=dztt;
driftinfo.binframesz=cfit1;
%
initaxis(par.resultstabgroup,'dz/frame final');
% hold off
plot(cfit1,dz,'x',framesall,dztt,'k')
% hold on
% plot(cfit1,dy,'o',framesall,dytt,'r')
xlabel('frame')
ylabel('dz (nm)')
drawnow
drift.z=dztt;
% asdafd
% fitposc=adddrift(positions,dxt,dyt); %recalculate positions
function [zpos,errz]= finddisplacementsZ % find displacements
binframes=2*ceil(numframes/timepoints/2+1);
frameranges=[firstframe:binframes:lastframe lastframe] ;
dnumframesh =length(frameranges);
zpos=zeros(dnumframesh-1);
errz=zpos+1;
timerh=tic;
for k=1:dnumframesh-1
indframek=pos.frame<frameranges(k+1)&pos.frame>=frameranges(k);
% posr.x=pos.xnm(indframe);posr.y=pos.ynm(indframe);
for l=k+1:dnumframesh-1
if toc(timerh)>.5
drawnow
timerh=tic;
plotaxish=plotaxis;
else
plotaxish=[];
end
indframel=pos.frame<frameranges(l+1)&pos.frame>=frameranges(l);
zpos(k,l)=finddisplacementZ(pos.xnm(indframek),pos.znm(indframek),pos.xnm(indframel),pos.znm(indframel),xb,zb,window, plotaxish);
zpos(l,k)=-zpos(k,l);
if SMAP_stopnow
error('execution stopped by user');
end
end
% disp(k/dnumframesh)
end
end
end
function [dx2,sdx2]=bindisplacementfit(ddx,errx)
% sf=size(ddx);
%idea: we measure displacements between every frames (dxik=xi-xk, xi is
%displacement for frame i). Use all xi as fit parameters, fit function
%calculates dxik. Robust fit.
% weights=1./(errx+.1).^2;
%startp
difddx=diff(ddx);
fp0=cumsum(median(difddx,2));
% fp0=zeros(sf(1)-1,1);
options=statset('nlinfit');
options=statset(options,'Robust','on');
[fp,r,J,COVB,mse] = nlinfit(ddx(:),ddx(:),@bindispf,fp0,options);
ci = nlparci(fp,r,'covar',COVB);
dx2=[0; fp];
% dx2=fp;
sx=ci(:,2)-ci(:,1);
sdx2=[mean(sx);sx];
end
function out=bindisp(fp,ddx)
fph=[0; fp];
ddxf=zeros(length(fph));
for k=1:length(fph)
ddxf(k,:)=fph(k)-fph; %calculate difference
end
% out=ddxf(:);
out=ddxf;
end
function out=bindispf(fp,ddx)
out=bindisp(fp);
out=out(:);
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/applydriftcorrection.m | .m | 1,314 | 32 | function poso=applydriftcorrection(drift,pos)
%pos: localizations with fields xnm ynm znm frame
indg=pos.frame>0;
if isfield(drift,'xy')
poso.xnm=pos.xnm;
poso.ynm=pos.ynm;
% for k=1:length(drit.xy)
if isfield(drift.xy(1),'x')
if strcmp(drift.xy(1).mirror,'horizontal')&&length(drift.xy)>1
indpos=pos.xnm<drift.xy(1).midpoint;
poso.xnm(indg&indpos)=pos.xnm(indg&indpos)-drift.xy(1).x(pos.frame(indg&indpos));
poso.xnm(indg&~indpos)=pos.xnm(indg&~indpos)-drift.xy(2).x(pos.frame(indg&~indpos));
else
poso.xnm(indg)=pos.xnm(indg)-drift.xy(1).x(pos.frame(indg));
end
end
if isfield(drift.xy(1),'y')
if strcmp(drift.xy(1).mirror,'vertical')&&length(drift.xy)>1
indpos=pos.ynm<drift.xy(2).midpoint;
poso.ynm(indg&indpos)=pos.ynm(indg&indpos)-drift.xy(1).y(pos.frame(indg&indpos));
poso.ynm(indg&~indpos)=pos.ynm(indg&~indpos)-drift.xy(2).y(pos.frame(indg&~indpos));
else
poso.ynm(indg)=pos.ynm(indg)-drift.xy(1).y(pos.frame(indg));
end
end
end
if isfield(drift,'z')&&isfield(pos,'znm')
poso.znm=pos.znm;
poso.znm(indg)=pos.znm(indg)-drift.z(pos.frame(indg));
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/driftcorrection3D_so.m | .m | 3,726 | 100 | function drift=driftcorrection3D_so(x,y,z,frame,p)
pard.correctxy=true; %correct in x, y
pard.drift_timepoints=10; %number of time points (blocks) in x,y,
pard.drift_pixrec=5; %size of pixels for reconstruction (in units of x,y, e.g. nm)
pard.drift_window=7; %Size of window in which maximum of cross-correlation is found (in reconstructed pixels).
pard.drift_maxdrift=1000; %maximum drift (in units of x, eg.g nm)
pard.drift_maxpixels=4096; %maximum size of reconstructed image (to avoid memory overflow).
pard.correctz=true; % correct in z;
pard.drift_timepointsz=20; %time points in z
pard.drift_pixrecz=5; %pixelsize for reconstruction in z (nm)
pard.drift_windowz=9; %size of window used for maximum finding
pard.zrange=[-300 300]; %range in z used for drift correction;
pard.slicewidth=200;% width of slice for z-correlation (in units of x, eg. nm)
pard.smoothmode.Value=2; %one of: '1: smoothing cubic spline','2: linear'
pard.smoothpar=[]; %smoothing parameter for cubic spline. Empty for automatic.
pard.drift_reference=false; %set true if reference is last frame;
pard.drift_mirror2c.Value=1; %one of: 1: 'no mirror', 2: '2 Channels, mirrored, vertical split', 3: '2 Channels, mirrored, horizontal split'
pard.showresults=true;
pard.maxframeall=max(frame); %range in frames (time) used for correction. Outside uses edge values
pard.framestart=min(frame);
pard.framestop=pard.maxframeall;
p=copyfields(pard,p);
p.roi=[min(x),min(y),max(x)-min(x),max(y)-min(y)]; %roi used (x,y,wx,wy)
f=figure;
p.resultstabgroup=uitabgroup(f);
if ~p.correctxy && ~p.correctz
return
end
locs.xnm=x;locs.ynm=y;locs.znm=z;locs.frame=frame;
[drift,driftinfo,fieldc]=getxyzdrift(locs,p);
% locsnew=applydriftcorrection(drift,locs);
end
function [drift,driftinfo,fieldc]=getxyzdrift(locs,p)
drift=[];driftinfo=[];
if p.correctxy
switch p.drift_mirror2c.Value
case 1 %all
ind=true(length(locs.xnm),1);
rep=false;
mirror='none';
midpoint=0;
p.repetitionname='';
case 2 %horizontal
midpoint=p.cam_pixelsize_nm(1)*(p.roi(1)+(p.roi(1)+p.roi(3))/2);
ind=locs.xnm<=midpoint;
rep=true;
mirror='horizontal';
p.repetitionname='1';
case 3 %vertical
midpoint=p.cam_pixelsize_nm(2)*(p.roi(2)+(p.roi(2)+p.roi(4))/2);
ind=locs.ynm<=midpoint;
rep=true;
mirror='vertical';
p.repetitionname='1';
end
[driftxy,driftinfoxy]=finddriftfeature(copystructReduce(locs,ind),p);
driftinfoxy.mirror=mirror; driftinfoxy.midpoint=midpoint;
driftinfo.xy=driftinfoxy;
drift.xy=copyfields([],driftxy,{'x','y'});
drift.xy(1).mirror=mirror;drift(1).xy(1).midpoint=midpoint;
if rep
p.repetitionname='2';
[driftxy,driftinfoxy]=finddriftfeature(copystructReduce(locs,~ind),p);
driftinfoxy.mirror=mirror; driftinfoxy.midpoint=midpoint;
driftinfo.xy(2)=(driftinfoxy);
drift.xy(2)=copyfields(drift.xy(1),driftxy,{'x','y'});
% drift.xy(2).mirror=mirror;drift(2).midpoint=midpoint;
end
end
if ~isempty(locs.znm)&&p.correctz
if p.correctxy
locsnew=copyfields(locs,applydriftcorrection(drift,locs),{'xnm','ynm'});
else
locsnew=locs;
drift=[];
end
[driftz,driftinfoz]=finddriftfeatureZ(locsnew,p);
drift.z=driftz.z;%copyfields(drift,driftz,'z');
driftinfo.z=driftinfoz;%copyfields(driftinfo,driftinfoz);
fieldc={'xnm','ynm','znm'};
else
fieldc={'xnm','ynm'};
end
% locsall=copyfields([],obj.locData.loc,{fieldc{:},'frame','filenumber'});
% locsnew=applydriftcorrection(drift,locsall);
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/robustMean.m | .m | 4,397 | 155 | function [finalMean, stdSample, inlierIdx, outlierIdx] = robustMean(data,dim,k,fit)
%ROBUSTMEAN calculates mean and standard deviation discarding outliers
%
% SYNOPSIS [finalMean, stdSample, inlierIdx, outlierIdx] = robustMean(data,dim,k,fit)
%
% INPUT data : input data
% dim : (opt) dimension along which the mean is taken {1}
% k : (opt) #of sigmas at which to place cut-off {3}
% fit : (opt) whether or not to use fitting to robustly estimate
% the mean from the data that includes outliers.
% 0 (default): mean is approximated by median(data)
% 1 : mean is approximated by
% fminsearch(@(x)(median(abs(data-x))),median(data))
% This option is only available for scalar data
%
%
% OUTPUT finalMean : robust mean
% stdSample : std of the data (divide by sqrt(n) to get std of the
% mean)
% inlierIdx : index into data with the inliers
% outlierIdx: index into data with the outliers
%
% REMARKS NaN or Inf will be counted as neither in- nor outlier
% The code is based on (linear)LeastMedianSquares. It could be changed to
% include weights
%
% c: jonas, 04/04
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% test input
if isempty(data)
error('Please supply non-empty data to robustMean')
end
if nargin<2 || isempty(dim)
% make sure that the dimensinon is correct if there's a vector
if any(size(data)==1) && ndims(data)==2
dim = find(size(data)>1);
else
dim = 1;
end
end
if nargin < 3 || isempty(k)
k = 3;
end
if nargin < 5 || isempty(fit)
fit = 0;
end
if fit == 1
% check for vector
if sum(size(data)>1)>1
error('fitting is currently only supported for 1D data')
end
end
if sum(isfinite(data(:))) < 4
warning('ROBUSTMEAN:INSUFFICIENTDATA',...
'Less than 4 data points!')
if isempty(dim)
dim=1;
end
finalMean = nanmean(data,dim);
% stdSample = NaN(size(finalMean));-
stdSample=nanstd(data,[],dim);
inlierIdx = find(isfinite(data));
outlierIdx = [];
return
end
%========================
% LEAST MEDIAN SQUARES
%========================
% define magic numbers:
%k=3; %cut-off is roughly at 3 sigma, see Danuser, 1992 or Rousseeuw & Leroy, 1987
magicNumber2=1.4826^2; %see same publications
% remember data size and reduced dataSize
dataSize = size(data);
reducedDataSize = dataSize;
reducedDataSize(dim) = 1;
% need this for later repmats
blowUpDataSize = dataSize./reducedDataSize;
% count how many relevant dimensions we have besides dim
realDimensions = length(find(dataSize>1));
% calc median - reduce dimension dim to length 1
if fit
% minimize the median deviation from the mean
medianData = fminsearch(@(x)(median(abs(data-x))),median(data));
else
medianData = nanmedian(data,dim);
end
% calculate statistics
res2 = (data-repmat(medianData,blowUpDataSize)).^2;
medRes2 = max(nanmedian(res2,dim),eps);
%testvalue to calculate weights
testValue=res2./repmat(magicNumber2*medRes2,blowUpDataSize);
if realDimensions == 1;
%goodRows: weight 1, badRows: weight 0
inlierIdx=find(testValue<=k^2);
outlierIdx = find(testValue>k^2);
% calculate std of the sample;
if nargout > 1
nInlier = length(inlierIdx);
if nInlier > 4
stdSample=sqrt(sum(res2(inlierIdx))/(nInlier-4));
else
stdSample = NaN;
end
end
%====END LMS=========
%======
% MEAN
%======
finalMean = mean(data(inlierIdx));
else
%goodRows: weight 1, badRows: weight 0
inlierIdx=find(testValue<=k^2);
outlierIdx=find(testValue > k^2);
% mask outliers
res2(outlierIdx) = NaN;
% count inliers
nInliers = sum(~isnan(res2),dim);
% calculate std of the sample;
if nargout > 1
% put NaN wherever there are not enough data points to calculate a
% standard deviation
goodIdx = sum(isfinite(res2),dim) > 4;
stdSample = NaN(size(goodIdx));
stdSample(goodIdx)=sqrt(nansum(res2(goodIdx),dim)./(nInliers(goodIdx)-4));
end
%====END LMS=========
%======
% MEAN
%======
data(outlierIdx) = NaN;
finalMean = nanmean(data,dim);
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/initaxis.m | .m | 1,231 | 57 | function [ax,tab]=initaxis(handle,name,option)
if nargin<3
option='';
end
if isa(handle,'matlab.ui.container.Tab')
tab=handle;
ax=tab.Children;
tabgroup=tab.Parent;
% state=tab.Parent.Parent.Visible;
if ~strcmp(option,'keep')
delete(handle.Children(:));
handle.Title=name;
ax=axes('Parent',handle);
end
elseif isa(handle,'matlab.ui.container.TabGroup')
% state=tab.Parent.Visible;
children=handle.Children;
found=0;
for k=1:length(children)
if strcmpi(name,children(k).Title)
found=1;
tab=children(k);
if ~strcmp(option,'keep')
delete(children(k).Children(:));
ax=axes('Parent',children(k));
else
ax=tab.Children;
end
break
end
end
if found==0
tab=uitab(handle,'Title',name);
ax=axes('Parent',tab);
end
tabgroup=handle;
elseif isa(handle,'Axes')
%
ax=handle;
delete(ax.Children(:));
tab=ax.Parent;
tabgroup=tab.Parent;
end
tabgroup.SelectedTab=tab;
state=tab.Parent.Parent.Visible;
axes(ax);
figure=tab.Parent.Parent;
figure.Visible=state;
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/mypeakfit.m | .m | 77 | 4 | function [xpos,fp]=mypeakfit(x,y)
fp=polyfit(x,y,2);
xpos=-fp(2)/2/fp(1);
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/copyfields.m | .m | 1,131 | 47 | function [destination,missing]=copyfields(destination,source,fields)
missing={};
if nargin==2 %copy all
if ~isempty(source)
if isa(destination,'handle')
fn=intersect(properties(destination),fieldnames(source));
else
fn=fieldnames(source);
end
for k=1:length(fn)
destination.(fn{k})=source.(fn{k});
end
end
elseif nargin>2
if ~iscell(fields)
fields={fields};
end
% fn=intersect(fields,fnsource);
if ~isempty(source)
indm=1;
fnsource=fieldnames(source);
% fnc=cellfun(@makehash,fnsource);
% tocopy=intersect(fnsource,fields);
% missing=setdiff(fields,fnsource);
% for k=1:length(tocopy)
% destination.(tocopy{k})=source.(tocopy{k});
% end
% fn=fields;
for k=1:length(fields)
if any(strcmp(fnsource,fields{k}))
destination.(fields{k})=source.(fields{k});
else
missing{indm}=fields{k};
indm=indm+1;
end
end
else
missing=fields;
end
end
function out=makehash(str)
out=sum(char(str));
% out=1;
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/histrenderc.c | .c | 2,900 | 114 | #include "mex.h"
#include <stdio.h>
//#include <math.h>
/*void correlate(double *n1, double *G, mwSize lenG, mwSize lenn)*/
double gaussrender(float *srim,float *xpix, float *ypix, mwSize *srec, float *sigma, float *Gtemplate, float Gsigma, float roiks, float *N, int uselut, float *c, float *lut, float *rangec, mwSize Gx,mwSize numlocs, mwSize sl)
{
mwSize Gsizegauss,indc,xt,yt,col,srimindlin;
float dx,dy,intcorrection,gaussnorm;
long k,dn,xr,yr,xax,yax,xp,yp;
double numberOfLocs;
Gsizegauss=(Gx-1)/2; /**/
for(k=0;k<numlocs;k++)
{
xr=xpix[k]+0.5;
yr=ypix[k]+0.5;
gaussnorm=N[k];
if(uselut==1)
indc=(c[k]-rangec[0])/(rangec[1]-rangec[0])*(sl-1);
if(xr>=0&&xr<srec[0]&&yr>=0&&yr<srec[1])
{
numberOfLocs++;
if(uselut==1)
{
if(indc>=0&indc<sl)
{
for(col=0;col<3;col++)
{
srimindlin=col*srec[1]*srec[0]+yr*srec[0]+xr;
srim[srimindlin]+=gaussnorm*lut[indc+col*sl];
}
}
}
else
{
srim[xr+yr*srec[0]]+=gaussnorm;
}
}
}
return numberOfLocs;
}
/* the gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
float *srim;
float *Gtemplate,*xpix,*ypix,*sigma,*N,*c;
float *lut,*rangec;
float Gsigma,roiks;
int uselut;
mwSize *srec,srec3[]={10,10,3};
double numberOfLocs;
mwSize Gx,Gy,numlocs,sl,sz;
/* xpix, ypix, srec, sigma, 4.Gtemplate, 5. Gsigma, roiks, 7. N, uselut, 9. c, 10. lut, 11. rangec */
/* create a pointer to the input matrix y */
xpix = (float*) mxGetData(prhs[0]);
ypix = (float*)mxGetData(prhs[1]);
srec = (mwSize*)mxGetData(prhs[2]);
sigma = (float*)mxGetData(prhs[3]);
Gtemplate = (float*)mxGetData(prhs[4]);
N = (float*)mxGetData(prhs[7]);
c = (float*)mxGetData(prhs[9]);
lut = (float*)mxGetData(prhs[10]);
rangec = (float*)mxGetData(prhs[11]);
/* get the dimensions of the matrix input y */
Gx = mxGetM(prhs[4]);
numlocs=mxGetM(prhs[0]);
sl=mxGetM(prhs[10]);
Gsigma=mxGetScalar(prhs[5]);
roiks=mxGetScalar(prhs[6]);
uselut=mxGetScalar(prhs[8]);
/* set the output pointer to the output matrix */
if(uselut==0)
{
srec3[2]=1;
}
srec3[0]=srec[0];
srec3[1]=srec[1];
plhs[0] = mxCreateNumericArray(3,srec3,mxSINGLE_CLASS,mxREAL);
/*printf("output size %i,%i,%i\n",srec3[0],srec3[1],sl);*/
/* create a C pointer to a copy of the output matrix */
srim = mxGetData(plhs[0]);
/* call the C subroutine */
numberOfLocs=gaussrender(srim,xpix, ypix, srec, sigma, Gtemplate, Gsigma, roiks, N, uselut, c, lut, rangec,Gx,numlocs,sl);
plhs[1]=mxCreateDoubleScalar(numberOfLocs);
}
| C |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/finddisplacementZ.m | .m | 1,290 | 62 | function zpos=finddisplacementZ(xr,zr,xt,zt,xb,zb,window,plotaxis)
if nargin<8
plotaxis=[];
end
if nargin<7
window=[];
end
[~,sindr]=sort(xr);
[~,sindt]=sort(xt);
x1r=1;x1t=1;
ccc=zeros(1,length(zb)*2-3);
for k=1:length(xb)-1
x2r=x1r;x2t=x1t;
while(xr(sindr(x2r))<xb(k+1))&&x2r<length(sindr)
x2r=x2r+1;
end
while(xt(sindt(x2t))<xb(k+1))&&x2t<length(sindt)
x2t=x2t+1;
end
zrh=zr(sindr(x1r:x2r-1));
zth=zt(sindt(x1t:x2t-1));
hr=histcounts(zrh,zb);
ht=histcounts(zth,zb);
hr=hr-mean(hr);
ht=ht-mean(ht);
ch=conv(hr,ht(end:-1:1),'full');
ccc=ccc+ch;
x1r=x2r;x1t=x2t;
end
[mc,ind]=max(ccc);
if isempty(window)
dh=find(ccc(ind:end)<mc/2,1,'first');
dh=max(3,round(dh/2));
else
dh=window;
end
zc=(-length(hr)+1:length(hr)-1)*(zb(2)-zb(1));
inrange=ind-dh:ind+dh;
inrange(zc(inrange)==0)=[];
zred=zc(inrange);
[zpos,fp]=mypeakfit(zc(inrange),ccc(inrange));
indplot=ind-3*dh:ind+3*dh;
if ~isempty(plotaxis) && indplot(1)>0 &&indplot(end)<=length(zc)
plot(plotaxis,zc(indplot),ccc(indplot),'x')
plotaxis.NextPlot='add';
plot(plotaxis,zred,fp(1)*zred.^2+zred*fp(2)+fp(3),'r');
plotaxis.NextPlot='replace';
title(plotaxis,['dz (mean): ' num2str(mean(zr)-mean(zt)) ', cc: ' num2str(zpos)])
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/copystructReduce.m | .m | 353 | 14 | function destination=copystructReduce(source,ind,fn)
if ~isempty(source)
if nargin<3
fn=fieldnames(source);
end
for k=1:length(fn)
if length(ind)==length(source.(fn{k}))||~islogical(ind)
destination.(fn{k})=source.(fn{k})(ind);
else
destination.(fn{k})=source.(fn{k});
end
end
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/histrender.m | .m | 3,631 | 115 | function [srim,nlocs,template]=histrender(pos,rangex, rangey, pixelsx, pixelsy, lut,rangec,template)
%pos.x, pos.y, pos.c, pos.N,pos.s
%global variables
if isfield(pos,'N')
N=pos.N;
else
N=ones(length(pos.x),1,'like',pos.x);
end;
if isfield(pos,'s')
spix=pos.s/pixelsx;
else
spix=0*pos.x+120;
end
roiks=2.5; %roiks*sigma: size of Roi used in units of sigma
G=creategausstemplate(roiks);
sG=size(G.template);
xpix=(pos.x-rangex(1))/pixelsx;ypix=(pos.y-rangey(1))/pixelsy; %renormalize x, y in units of pixelsize (reconsturcted image)
if nargin<6||length(lut)==1 %only one color
uselut=0;
srec(3)=1;
lut=0;pos.c=0;rangec=[0,0];
else
uselut=1;
srec(3)=3;
% pos.s(pos.s<1)=.2;
% pos.c(pos.c>rangec(2))=rangec(2);
% pos.c(pos.c<rangec(1))=rangec(1);
end
srec(1)=round((rangex(2)-rangex(1))/pixelsx); %size of reconstructed image. maybe ceil is better?
srec(2)=round((rangey(2)-rangey(1))/pixelsy);
% srim=gaussrenderi(xpix,ypix,srec,pos.s,G.template,G.sigmatemplate,roiks,N,uselut,pos.c,lut, rangec);
[srim,nlocs]=histrenderc(single(xpix-1),single(ypix-1),uint32(srec),single(spix),single(G.template),single(G.sigmatemplate),...
single(roiks),single(N),int32(uselut),single(pos.c),single(lut), single(rangec));
srim=permute(srim,[2 1 3]);
end
%
% figure(3);
% subplot(2,2,2);imagesc(srimc/max(srimc(:)))
% title(sum(srimc(:)))
% colorbar
% subplot(2,2,1);imagesc(srim/max(srim(:)))
% title(max(srim(:)))
% colorbar
% imdiff=srim-srimc;
% subplot(2,2,3);imagesc(imdiff/max(imdiff(:)))
% title(max(imdiff(:)))
% colorbar
% function srim=gaussrenderi(xpix,ypix,srec,sigma,Gtemplate,Gsigma,roiks,N,uselut,c,lut, rangec)
% s=size(Gtemplate);
% Gsizegauss=(s(1)-1)/2;
% sl=length(lut);
% srim=zeros(srec);
% for k=1:length(xpix) %all localizations
% dn=ceil(roiks*sigma(k));
% xr=round(xpix(k));yr=round(ypix(k));
% dx=xpix(k)-xr;dy=ypix(k)-yr;
% intcorrection=erf((dn+0.5)/sigma(k)/sqrt(2))^2; %integrate(G,-k sigma, k sigma)= (Erf (k/sqrt(2)))^2: normalization. 0.5: since -dn:dn
% gaussnorm=N(k)/(2*pi*sigma(k)^2*intcorrection);
% if uselut
% indc=ceil((c(k)-rangec(1))/(rangec(2)-rangec(1))*(sl));
% end
%
% for xax=-dn:dn
% xt=round((xax-dx)*Gsigma/sigma(k))+Gsizegauss+1;
% for yax=-dn:dn
% yt=round((yax-dy)*Gsigma/sigma(k))+Gsizegauss+1;
% xp=xr+xax;yp=yr+yax;
% if xp>0&&xp<=srec(1) && yp>0&&yp<=srec(2)
% if uselut
% for col=1:3
% srim(xp+(yp-1)*srec(1)+(col-1)*srec(1)*srec(2))=srim(xp+(yp-1)*srec(1)+(col-1)*srec(1)*srec(2))...
% +Gtemplate(xt+(yt-1)*sG(1))*gaussnorm*lut(indc+(col-1)*length(lut));
% % srim(xp,yp,col)=srim(xp,yp,col)+Gtemplate(xt,yt)*gaussnorm*lut(indc,col);
% end
% else
% srim(xp,yp)=srim(xp,yp)+Gtemplate(xt,yt)*gaussnorm;
% end
% end
% end
% end
%
% end
%
% end
% end
function gausstemplate=creategausstemplate(roiks) % create template
% global gausstemplate
% sigmatemplate=10;
sizegauss=5;
sigmatemplate=(sizegauss)/(2*roiks)/2; %for 2.5 sigma in both directions
xg=-sizegauss:sizegauss;
[Xg,Yg]=meshgrid(xg,xg);
template=exp(-((Xg).^2+(Yg).^2)/2/sigmatemplate^2);
gausstemplate.template=template;
gausstemplate.sizegauss=sizegauss;
gausstemplate.sigmatemplate=sigmatemplate;
end
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/driftCorrection/private/my2Dgaussfit.m | .m | 9,042 | 344 | function [fitpos,outim,outimnorm,ci]=my2Dgaussfit(image,startp,cas)
%fit par=(x,y,a,bg,sx,sy,r)
if nargin<3
cas=2;
show=false;
end
if nargout>1
show=true;
end
% if ishandle(show)
% hfig=show;
% show=true;
% elseif show
% hf=figure(2);
% hfig=axes('Parent',hf);
% end
% %normalize by max pixel
% maximage=max(image(:));
% image=image/maximage;
weighted=0;
switch cas
case 1 %only x, y
fitinit.fitf=@gaussPALMVfix; fitinit.nfitp=4;
case 2% also sigma
fitinit.fitf=@gaussPALMVsigma; fitinit.nfitp=5;
case 3 %sx sy rho
fitinit.fitf=@gaussPALMVfree; fitinit.nfitp=7;
end
%determine startparameters
s=size(image);
xi=1:s(2);
yi=1:s(1);
gxi=sum(image,1);
gyi=sum(image,2)';
xm=sum(xi.*gxi)/sum(gxi);
ym=sum(yi.*gyi)/sum(gyi);
gxi(gxi<0)=0;gyi(gyi<0)=0;
sxm=sqrt(sum((xi-xm).^2.*gxi)/sum(gxi));
sym=sqrt(sum((yi-ym).^2.*gyi)/sum(gyi));
if ~isreal(sxm)
sxm=1;
end
if ~isreal(sym)
sym=1;
end
[Xi,Yi]=meshgrid(xi,yi);
rsxsy= sum( sum((Xi-xm).*(Yi-ym).*image))/sum(image(:));
rho=rsxsy/sxm/sym;
bg=min(image(:));
a=max(image(:))-bg;
% rho=0;
%startparameter
% sx=startp(5);
% sy=startp(6); rho=startp(7);
mIter=100;
%construct matrix and grid
% fitp.V=[sx^2,rho*sx*sy;rho*sx*sy,sy^2];
fitp.V=[sxm^2,rho*sxm*sym;rho*sxm*sym,sym^2];
fitp.Vinv=inv(fitp.V);
s=size(image);
x=1:s(1);
y=1:s(2);
[fitp.X,fitp.Y]=meshgrid(x,y);
fitinit.fitp=fitp;
%handle to function with differences
fitferr=str2func([func2str(fitinit.fitf) 'err']);
% %initialize fi
% oldopts=optimset('lsqnonneg');
oldopts=optimset('lsqnonlin');
% options=optimset(oldopts,'TolX',10^-6,'TolFun',10^-6,'Jacobian','on','Algorithm',{'levenberg-marquardt',0.005},'Display','on','Diagnostics','off','MaxIter',mIter);
options=optimset(oldopts,'TolX',10^-6,'TolFun',10^-6,'Jacobian','on','Display','off','Diagnostics','off','MaxIter',mIter);
%initialize mYlsq
%x,y, A,BG,V1, V2, V4
% fitinit.startp=double([startp(1),startp(2),100,min(image(:)),fitp.Vinv([1 2 4])]);
% fitinit.lsqstruc =mYlsqnonlininit(fitferr,fitinit.startp(1:fitinit.nfitp),[],[], options,fitp,fitp.X); %fitp.X dummy insize of smallframe
fitinit.startp=double([xm,ym,a,bg,fitp.Vinv([1 2 4])]);
if ~isempty(find(isnan(fitinit.startp)))
fitinit.startp=zeros(8,1);
end
startph=fitinit.startp(1:fitinit.nfitp);
% startph(4)=startp(4);
% startph(3)=startp(3);
if weighted
image=sqrt(image);
end
[fitout,resnorm,residual,exitflag,output,lambda,jacobian] =lsqnonlin(fitferr,startph,[],[], options,fitp,image);
fitpos=fitout2fitpos(fitout,0,0,fitinit.nfitp,fitinit.startp);
if weighted
chi2=(resnorm)/((s(1)*s(2))-fitinit.nfitp-1);
else
chi2=sum(residual(:).^2./image(:))/((s(1)*s(2))-fitinit.nfitp-1);
end
fitpos(9)=chi2;
fitpos(8)=output.funcCount;
% fitpos(3:4)=fitpos(3:4)*maximage;
ci=nlparci(fitout,residual,'jacobian',jacobian);
if show
im2=fitinit.fitf(startph,fitinit.fitp);
im3=fitinit.fitf(fitout,fitinit.fitp);
im4=fitinit.fitf(fitout,fitinit.fitp)-image;
outim=[image,im2;im3,im4];
outimnorm=[imnorm(image),imnorm(im2);imnorm(im3),imnorm(im4)];
% imagesc([image,im2;im3,im4],'Parent',hfig)
% waitforbuttonpress
% drawnow
end
function fitpos=fitout2fitpos(fitout,mx,my,nfitp,startp)
fitpos(1)=fitout(2)+mx;
fitpos(2)=fitout(1)+my; %%%%%%%%%%%%%%%%%%%%%%%%%%%% careful
fitpos(3:4)=fitout(3:4);
if nfitp==4
fitpos(5)=Vinv2sigma(startp(5));
fitpos(6)=fitpos(5); %sx=xy
fitpos(7)=0; %rho=0
elseif nfitp==5
fitpos(5)=Vinv2sigma(fitout(5));
fitpos(6)=fitpos(5); %sx=xy
fitpos(7)=0;
elseif nfitp==7
fitpos(5:7)=Vinv2sigma(fitout(5),fitout(6),fitout(7));
else
disp('error')
end
function [out,J]=gaussPALMVfixerr(par,fitp,frame)
if nargout==1
out=gaussPALMVfix(par,fitp)-(frame);
else
[fitframe,J]=gaussPALMVfix(par,fitp);
out=fitframe-frame;
end
out=out(:);
function [out,J]=gaussPALMVfix(par,fitp)
%matrix fix. free parameters: x0,y0,b,A
x0=par(1);y0=par(2);A=par(3);b=par(4);
xpon=-0.5*(fitp.Vinv(1,1)*(fitp.X-x0).^2+2*fitp.Vinv(1,2)*(fitp.X-x0).*(fitp.Y-y0)+fitp.Vinv(2,2)*(fitp.Y-y0).^2);
FA=exp(xpon);
out=A*FA+b;
if nargout>1
x1=A*FA.* (fitp.Vinv(1,1)*(fitp.X - x0) + fitp.Vinv(1,2)*(fitp.Y - y0));
x2=A* FA.*(fitp.Vinv(1,2)*(fitp.X - x0) + fitp.Vinv(2,2)*(fitp.Y - y0));
x3= FA;
x4=ones(length(FA));
J=[x1(:),x2(:),x3(:),x4(:)];
% size(J)
end
function [out,J]=gaussPALMVfreeerr(par,fitp,frame)
if nargout==1
out=(frame)-gaussPALMVfree(par,fitp);
else
[fitframe,J]=gaussPALMVfree(par,fitp);
out=fitframe-frame;
end
function [out,J]=gaussPALMVfree(par,fitp)
%matrix fix. free parameters: x0,y0,b,A,V11,V12,V22
x0=par(1);y0=par(2);A=par(3);b=par(4);V11=par(5);V12=par(6);V22=par(7);
xpon=-0.5*(V11*(fitp.X-x0).^2+2*V12*(fitp.X-x0).*(fitp.Y-y0)+V22*(fitp.Y-y0).^2);
FA=exp(xpon);
out=A*FA+b;
if nargout>1
x1=A*FA.* (V11*(fitp.X - x0) + V12*(fitp.Y - y0));
x2=A* FA.*(V12*(fitp.X - x0) + V22*(fitp.Y - y0));
x3= FA;
x4=ones(length(FA));
x5=-A*FA.* ((fitp.X - x0).^2)/2;
x6=-A*FA.* (fitp.X - x0).*(fitp.Y - y0);
x7=-A*FA.* ((fitp.Y - y0).^2)/2;
J=[x1(:),x2(:),x3(:),x4(:),x5(:),x6(:),x7(:)];
% size(J)
end
function [out,J]=gaussPALMVsigmaerr(par,fitp,frame)
if nargout==1
out=gaussPALMVsigma(par,fitp)-(frame);
else
[fitframe,J]=gaussPALMVsigma(par,fitp);
out=fitframe-frame;
end
out=out(:);
function [out,J]=gaussPALMVsigma(par,fitp)
%matrix fix. free parameters: x0,y0,b,A
x0=par(1);y0=par(2);A=par(3);b=par(4);Vi1=par(5);
xpon=-0.5*(Vi1*(fitp.X-x0).^2+Vi1*(fitp.Y-y0).^2);
FA=exp(xpon);%no norm
out=A*FA+b;
if nargout>1
x1=A*FA.* (Vi1*(fitp.X - x0));
x2=A* FA.*( Vi1*(fitp.Y - y0));
x3= FA;
x4=ones(length(FA));
x5=-A*FA/2.*((fitp.X - x0).^2+(fitp.Y - y0).^2);
J=[x1(:),x2(:),x3(:),x4(:),x5(:)];
% size(J)
end
function s= Vinv2sigma(V11,V12,V22)
if nargin==3
s=real([sqrt(V22./(-V12.^2 + V11.*V22)), sqrt(V11./(-V12.^2 + V11.*V22)), V12./sqrt(V11.*V22)]);
elseif nargin==1;
s=real(1/sqrt(V11));
elseif nargin==0;
s=[];
end
function V= sigma2Vinv(sx,sy,r)
V=[(sx.^2 - r.^2.*sx.^2).^(-1), -(r./(sx.*sy - r.^2.*sx.*sy)), (sy.^2 - r.^2.*sy.^2).^(-1)];
function [out,J]=gaussPALMVfixwerr(par,fitp,frame)
if nargout==1
out=gaussPALMVfixw(par,fitp)-(frame);
else
[fitframe,J]=gaussPALMVfixw(par,fitp);
out=fitframe-frame;
end
out=out(:);
function [out,J]=gaussPALMVfixw(par,fitp)
%matrix fix. free parameters: x0,y0,b,A
x0=par(1);y0=par(2);A=par(3);b=par(4);
xpon=-0.5*(fitp.Vinv(1,1)*(fitp.X-x0).^2+2*fitp.Vinv(1,2)*(fitp.X-x0).*(fitp.Y-y0)+fitp.Vinv(2,2)*(fitp.Y-y0).^2);
FA=exp(xpon);
out=sqrt(A*FA+b);
if nargout>1
x4=0.5./out; %ok
x3= FA.*x4; %ok
x1=A*x3.* (fitp.Vinv(1,1)*(fitp.X - x0) + fitp.Vinv(1,2)*(fitp.Y - y0));
x2=A* x3.*(fitp.Vinv(1,2)*(fitp.X - x0) + fitp.Vinv(2,2)*(fitp.Y - y0));
J=[x1(:),x2(:),x3(:),x4(:)];
% size(J)
end
function [out,J]=gaussPALMVsigmawerr(par,fitp,frame)
if nargout==1
out=gaussPALMVsigmaw(par,fitp)-(frame);
else
[fitframe,J]=gaussPALMVsigmaw(par,fitp);
out=fitframe-frame;
end
out=out(:);
function [out,J]=gaussPALMVsigmaw(par,fitp)
%matrix fix. free parameters: x0,y0,b,A
x0=par(1);y0=par(2);A=par(3);b=par(4);Vi1=par(5);
xpon=-0.5*(Vi1*(fitp.X-x0).^2+Vi1*(fitp.Y-y0).^2);
FA=exp(xpon);%no norm
out=sqrt(A*FA+b);
if nargout>1
x4=0.5./out; %ok
x3= FA.*x4; %ok
x1=A*x3.* (Vi1*(fitp.X - x0));
x2=A* x3.*( Vi1*(fitp.Y - y0));
x5=-A*x3/2.*((fitp.X - x0).^2+(fitp.Y - y0).^2);
J=[x1(:),x2(:),x3(:),x4(:),x5(:)];
% size(J)
end
function [out,J]=gaussPALMVfreewerr(par,fitp,frame)
if nargout==1
out=(frame)-gaussPALMVfreew(par,fitp);
else
[fitframe,J]=gaussPALMVfreew(par,fitp);
out=fitframe-frame;
end
function [out,J]=gaussPALMVfreew(par,fitp)
%matrix fix. free parameters: x0,y0,b,A,V11,V12,V22
x0=par(1);y0=par(2);A=par(3);b=par(4);V11=par(5);V12=par(6);V22=par(7);
xpon=-0.5*(V11*(fitp.X-x0).^2+2*V12*(fitp.X-x0).*(fitp.Y-y0)+V22*(fitp.Y-y0).^2);
FA=exp(xpon);
out=sqrt(A*FA+b);
if nargout>1
x4=0.5./out; %ok
x3= FA.*x4; %ok
x1=A*x3.* (V11*(fitp.X - x0) + V12*(fitp.Y - y0));
x2=A* x3.*(V12*(fitp.X - x0) + V22*(fitp.Y - y0));
x5=-A*x3.* ((fitp.X - x0).^2)/2;
x6=-A*x3.* (fitp.X - x0).*(fitp.Y - y0);
x7=-A*x3.* ((fitp.Y - y0).^2)/2;
J=[x1(:),x2(:),x3(:),x4(:),x5(:),x6(:),x7(:)];
% size(J)
end
function imout=imnorm(imin)
minim=min(imin(:));maxim=max(imin(:));
imout=(imin-minim)/(maxim-minim);
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/wobble/simBeadLocCorr.m | .m | 931 | 27 | function [xnm, ynm, frame_out] = simBeadLocCorr(xnm, ynm, frame, gt)
%In case of exceeding number of localizations wrt expected one, pick the closest ones to the
%bead positions, not improving the results (even worse).
%DEPRECATED, not used
warning('warning : the function simBeadLocCorr should not be called');
nBeads = size(gt,1);
%frame_out = repmat(1:max(frame),[nBeads,1]); frame_out = frame_out(:);
frame_out = [];
for n=1:max(frame)
ind = frame==n;
if nnz(ind) > nBeads
loc_frame = [xnm(ind), ynm(ind)];
nLoc = size(loc_frame,1);
pos2keep = knnsearch(loc_frame, gt, 'K',1);
loc_frame(~ismember(1:nLoc, pos2keep),:) = nan;
xnm(ind) = loc_frame(:,1);
ynm(ind) = loc_frame(:,2);
frame_out = [frame_out;ones(nBeads,1)*n];
elseif nnz(ind) < nBeads
frame_out = [frame_out;ones(nnz(ind),1)*n];
end
end
xnm(isnan(xnm)) = [];
ynm(isnan(ynm)) = [];
end | MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/wobble/wobbleCalibration.m | .m | 28,199 | 988 | function [wobbleMatrix] = wobbleCalibration(x,y,z,nBead,varargin)
% WOBBLECALIBRATION Generate correction data for z-dependent "wobble"
%
% MODIFIED BY THANH-AN 24th May 2016
%
% SYNTAX
% [wobbleMatrix]=wobbleCalibration(x,y,z,nBead)
% [wobbleMatrix]=wobbleCalibration(..., 'SaveWobbleFile',wobbleFileName)
% [wobbleMatrix]=wobbleCalibration(..., 'ZLimit',zLim)
% [wobbleMatrix]=wobbleCalibration(..., 'NumSplineBreak',nBreak)
%
% INPUTS
% x,y,z: A dataset containing the observed localizations 'x,y' of beads at known position 'z'
% Usually generated by imaging fluorescent beads, stepped through z with a
% z-piezo stage. Normally, the exact same data used to generate an astigmatic
% 3D PSF width calibration is used.
% nBead: The number of 'good' (ie non-aggregated beads) in the image, which will
% be manually selected.
% OUTPUTS
% wobbleMatrix
% Lookup table containing a list of axial shifts
% as a function of Z, ie
% wobbleData = [Z1, xShift1, yShift1;...
% Z2, xShift2, yShift2;... etc]
% DESCRIPTION
% [wobbleMatrix]=wobbleCalibration(x,y,z,nBead)
% Plots the bead localizations and prompts the user to manually select 'nBead'
% regions within the image containing only localizations from a single bead.
% The xy-wobble is calculated as a function of z for each bead via spline fitting, and plotted.
% The combined xy-wobble is calculated via a second spline fit to exclude outliers usually arising
% from aggregated or overlapping beads.
% A wobble lookup table 'wobbleMatrix' is generated, which may be used for subsequent correction
% of 3D localization data.
%
% OPTIONS
% [wobbleMatrix]=wobbleCalibration(..., 'SaveWobbleFile',wobbleFileName)
% Save the 'wobbleMatrix' to a text file 'wobbleFileName'
% [wobbleMatrix]=wobbleCalibration(..., 'ZLimit',zLim)
% Only produce a wobble lookup table over specified limits
% zLim = [zMin zMax]. This is useful for excluding regions where fitting is unreliable
% because the beads have become too defocussed. Ie, bead calibration data is usually
% taken over a large Z range. This allows cropping to only the useful z-range
% [wobbleMatrix]=wobbleCalibration(..., 'NumSplineBreak',nBreak)
% Set the number of breaks 'nBreak' (default = 10) to use in the spline fit. If the resolution of the
% spline is insufficient compared to the underlying data, consider increasing 'nBreak'
% [wobbleMatrix]=wobbleCalibration(..., 'ROI',ROI)
% Provides the beads ROIs instead of the manual selection
% [wobbleMatrix]=wobbleCalibration(..., 'Zfit',zfit)
% Set the z-slice for which the XY correction are calculated (e.g.
% -750 nm to 750 nm every 10 nm.
% [wobbleMatrix]=wobbleCalibration(..., 'GT',gt)
% Calculate the xy-shift wrt the ground truth gt instead of the xy @z=0
% It doesn't matter if the beads positions are unordered wrt ROI
% EXAMPLE
% Generate a wobble correction lookup table for the test data supplied with these functions.
%
% The test data below ('bead 0.1um -1.5to1.5 20nm Z-step 3D cal.txt') shows fluorescent beads
% (Invitrogen 0.1um TetraSpeks), stepped in Z with a piezo stage and 2D localized with RapidSTORM
% in X,Y. Z was set to the known position of the piezo via RapidSTORM. This dataset can similarly
% be used to generate a PSF width 3D lookup table for astigmatic Z-localization (see the
% RapidSTORM 3.3 manual for further instructions on how to do this).
%
% Load the x,y,z data (this is the test data supplied with the
% wobble correction functions):
% fname = 'test data\bead 0.1um -1.5to1.5 20nm Z-step 3D cal.txt'
% a=importdata(fname);data=a.data;
% x = data(:,1); y=data(:,3);z=data(:,5);
% You also need to tell the progam how many good beads are in the image. Do this by loading
% up the localizations in your favorite PALM visualization software (eg PALMsiever
% https://github.com/PALMsiever/palm-siever), and counting how many good beads you have
% nBead = 7;
% Run the calibration, saving the output
% [wobbleMatrix]=wobbleCalibration(x,y,z,nBead,'SaveWobbleFile','Wobble-cal test.txt');
% A scatter plot of the XY localizations will appear, you will be prompted to select 'nBead'
% (here, 7) rectangular bead-containing regions.
% Once selected, a plot of XY-wobble vs z for each bead should be generated, together
% with combined fits for all beads.
% Note that the fit, and hence wobble correction, becomes unreliable once the beads go
% out of focus (here z<-750 and z>850). In practice, Z-localization in these regions is also
% unlikely to be feasible. Therefore, exclude these regions from the lookup table,
% either by manually editing the wobble file, or by re-running the calibration with:
% [wobbleMatrix]=wobbleCalibration(x,y,z,nBead, ...,
% 'SaveWobbleFile','Wobble-cal test.txt','ZLimit',[-750 850]);
% The advantage of rerunning the calibration like this is that the (default) 10 spline points
% are spread over a smaller range, giving higher resolution to the spline fit. Alternatively
% run the entire range with a higher number of spline points to begin with:
% [wobbleMatrix]=wobbleCalibration(x,y,z,nBead, ...,
% 'SaveWobbleFile','Wobble-cal test.txt','NumSplineBreak',20);
% and manually crop the text file later.
%
% The generated wobbleMatrix may now be used for wobble correction. See CORRECTWOBBLE documentation
% for details.
%
% This software is released under the GPL v3 (see license file 'gpl.txt'). It is provided AS-IS and no
% warranty is given.
%
% Author: Seamus Holden
% Last update: April 2015
narg = numel(varargin);
nBreak = 10;
zLim = [-Inf Inf];
ii=1;
%doSaveFile = false;
hasROI = false;
wobbleSaveName = [];
zfit = [];
gt = [];
while ii<=narg
if strcmp(varargin{ii},'NumSplineBreak')
nBreak= varargin{ii+1};
ii = ii+2;
elseif strcmp(varargin{ii},'ZLimit')
zLim= varargin{ii+1};
ii = ii+2;
elseif strcmp(varargin{ii},'SaveWobbleFile')
wobbleSaveName= varargin{ii+1};
ii = ii+2;
elseif strcmp(varargin{ii},'ROI')
hasROI = true;
ROI = varargin{ii+1};
ii = ii+2;
elseif strcmp(varargin{ii},'Zfit')
zfit = varargin{ii+1};
ii = ii + 2;
elseif strcmp(varargin{ii},'GT')
gt = varargin{ii+1};
ii = ii + 2;
else
ii = ii+1;
end
end
%Modified by Thanh-an Pham the 16th May 2016
if hasROI
for ii = 1:nBead
bead{ii} = [ROI(ii,1),ROI(ii,2),ROI(ii,3) + ROI(ii,1), ROI(ii,4) + ROI(ii,2)];
end
else
figure;
hF = scatter(x,y,25,z,'.');
set(gca,'YDir','reverse')
for ii = 1:nBead
hR{ii} = imrect(hF);
bead{ii} = getPosition(hR{ii});
bead{ii}(3) = bead{ii}(3) + bead{ii}(1);
bead{ii}(4) = bead{ii}(4) + bead{ii}(2);
end
end
% bead lim are [xmin, ymin, xmax, ymax]
[z,xWobble, yWobble] = xyWobble(x,y,z,bead,zLim,wobbleSaveName,nBreak,zfit,gt);
wobbleMatrix = [z(:),xWobble(:),yWobble(:)];
%---------------------------------------------------
function [zfit,xWobble, yWobble] = xyWobble(x,y,z,beadLim,zlim,fsavename,nBreak,zfit,gt)
WOBBLEWARNINGNM = 500;%warn if values greater than this
bead = beadLim;
n = numel(bead);
zAll = [];
gt_tmp = gt;
k=1;
for ii = 1:n
isBead = x>bead{ii}(1) & y>bead{ii}(2) & x<bead{ii}(3) & y<bead{ii}(4);
xBead{ii} = x(isBead);
yBead{ii} = y(isBead);
zBead{ii} = z(isBead);
%reorder ground truth
for jj = 1:n
if ~isempty(gt_tmp) &&...
gt_tmp(jj,1) > bead{ii}(1) && gt_tmp(jj,2) > bead{ii}(2) &&...
gt_tmp(jj,1) < bead{ii}(3) && gt_tmp(jj,2) < bead{ii}(4)
gt(ii,:) = gt_tmp(jj,:);
end
end
zAll = [zAll;z(isBead)];
end
isOk = zAll>zlim(1)&zAll<zlim(2);
zRangeSet = zAll(isOk);
%Modified by Thanh-an Pham 16.05.2016
if isempty(zfit)
zfit = min(zRangeSet): (max(zRangeSet)-min(zRangeSet))/nBreak:max(zRangeSet);
%zfit = -750:10:750;
end
for ii =1:n
xWobble = fit1Spline(xBead{ii},zBead{ii},zfit,nBreak);
yWobble = fit1Spline(yBead{ii},zBead{ii},zfit,nBreak);
beadFit{ii} = [zfit(:), xWobble(:),yWobble(:)];
end
if isempty(gt)
%find the zfit point nearest to zero, align everything on this
[~, idx] =min(abs(zfit));
for ii =1:n
%shift x
beadFit{ii}(:,2) = beadFit{ii}(:,2) - beadFit{ii}(idx,2);
%shift y
beadFit{ii}(:,3) = beadFit{ii}(:,3) - beadFit{ii}(idx,3);
end
else
%use the ground truth gt for xy for each z
for ii = 1:n
%shift x
beadFit{ii}(:,2) = beadFit{ii}(:,2) - gt(ii,1);
%shift y
beadFit{ii}(:,3) = beadFit{ii}(:,3) - gt(ii,2);
end
end
%combine all the spline fits, one more spline fit to generate the final data
z=[];x=[];y=[];
for ii =1:n
z= [z;beadFit{ii}(:,1)];
x= [x;beadFit{ii}(:,2)];
y= [y;beadFit{ii}(:,3)];
end
xWobble = fit1Spline(x,z,zfit,nBreak);
yWobble = fit1Spline(y,z,zfit,nBreak);
%plot
figure;hold all
plot(zfit,xWobble,'r');
plot(zfit,yWobble,'b');
for ii = 1:n
plot(beadFit{ii}(:,1),beadFit{ii}(:,2),'k');
plot(beadFit{ii}(:,1),beadFit{ii}(:,3),'g');
end
legend('X, combined fit','Y, combined fit', 'X, single bead fit', 'Y, single bead fit');
xlabel('Z (nm)');
ylabel('XY wobble (nm)')
%saveas(gcf,'XY wobble result.fig');
%saveas(gcf,'XY wobble result.png');
calData = [zfit(:), xWobble(:),yWobble(:)];
if ~isempty(fsavename)
dlmwrite(fsavename, calData,' ');
end
if any([xWobble(:);yWobble(:)]>=WOBBLEWARNINGNM)
warning(['Wobble correction values > ', num2str(WOBBLEWARNINGNM),' nm detected, please check the input data for errors.']);
end
%-----------------------------------------
function [xfit] = fit1Spline(x,t,tfit,nBreak)
%fit with splinefit
ppX=splinefit(t,x,nBreak,'r');
xfit = ppval(ppX,tfit);
%-----------------------------------------
function pp = splinefit(varargin)
%SPLINEFIT Fit a spline to noisy data.
% PP = SPLINEFIT(X,Y,BREAKS) fits a piecewise cubic spline with breaks
% (knots) BREAKS to the noisy data (X,Y). X is a vector and Y is a vector
% or an ND array. If Y is an ND array, then X(j) and Y(:,...,:,j) are
% matched. Use PPVAL to evaluate PP.
%
% PP = SPLINEFIT(X,Y,P) where P is a positive integer interpolates the
% breaks linearly from the sorted locations of X. P is the number of
% spline pieces and P+1 is the number of breaks.
%
% OPTIONAL INPUT
% Argument places 4 to 8 are reserved for optional input.
% These optional arguments can be given in any order:
%
% PP = SPLINEFIT(...,'p') applies periodic boundary conditions to
% the spline. The period length is MAX(BREAKS)-MIN(BREAKS).
%
% PP = SPLINEFIT(...,'r') uses robust fitting to reduce the influence
% from outlying data points. Three iterations of weighted least squares
% are performed. Weights are computed from previous residuals.
%
% PP = SPLINEFIT(...,BETA), where 0 < BETA < 1, sets the robust fitting
% parameter BETA and activates robust fitting ('r' can be omitted).
% Default is BETA = 1/2. BETA close to 0 gives all data equal weighting.
% Increase BETA to reduce the influence from outlying data. BETA close
% to 1 may cause instability or rank deficiency.
%
% PP = SPLINEFIT(...,N) sets the spline order to N. Default is a cubic
% spline with order N = 4. A spline with P pieces has P+N-1 degrees of
% freedom. With periodic boundary conditions the degrees of freedom are
% reduced to P.
%
% PP = SPLINEFIT(...,CON) applies linear constraints to the spline.
% CON is a structure with fields 'xc', 'yc' and 'cc':
% 'xc', x-locations (vector)
% 'yc', y-values (vector or ND array)
% 'cc', coefficients (matrix).
%
% Constraints are linear combinations of derivatives of order 0 to N-2
% according to
%
% cc(1,j)*y(x) + cc(2,j)*y'(x) + ... = yc(:,...,:,j), x = xc(j).
%
% The maximum number of rows for 'cc' is N-1. If omitted or empty 'cc'
% defaults to a single row of ones. Default for 'yc' is a zero array.
%
% EXAMPLES
%
% % Noisy data
% x = linspace(0,2*pi,100);
% y = sin(x) + 0.1*randn(size(x));
% % Breaks
% breaks = [0:5,2*pi];
%
% % Fit a spline of order 5
% pp = splinefit(x,y,breaks,5);
%
% % Fit a spline of order 3 with periodic boundary conditions
% pp = splinefit(x,y,breaks,3,'p');
%
% % Constraints: y(0) = 0, y'(0) = 1 and y(3) + y"(3) = 0
% xc = [0 0 3];
% yc = [0 1 0];
% cc = [1 0 1; 0 1 0; 0 0 1];
% con = struct('xc',xc,'yc',yc,'cc',cc);
%
% % Fit a cubic spline with 8 pieces and constraints
% pp = splinefit(x,y,8,con);
%
% % Fit a spline of order 6 with constraints and periodicity
% pp = splinefit(x,y,breaks,con,6,'p');
%
% See also SPLINE, PPVAL, PPDIFF, PPINT
% Author: Jonas Lundgren <splinefit@gmail.com> 2010
% 2009-05-06 Original SPLINEFIT.
% 2010-06-23 New version of SPLINEFIT based on B-splines.
% 2010-09-01 Robust fitting scheme added.
% 2010-09-01 Support for data containing NaNs.
% 2011-07-01 Robust fitting parameter added.
% Check number of arguments
narginchk(3,7);
% Check arguments
[x,y,dim,breaks,n,periodic,beta,constr] = arguments(varargin{:});
% Evaluate B-splines
base = splinebase(breaks,n);
pieces = base.pieces;
A = ppval(base,x);
% Bin data
[junk,ibin] = histc(x,[-inf,breaks(2:end-1),inf]); %#ok
% Sparse system matrix
mx = numel(x);
ii = [ibin; ones(n-1,mx)];
ii = cumsum(ii,1);
jj = repmat(1:mx,n,1);
if periodic
ii = mod(ii-1,pieces) + 1;
A = sparse(ii,jj,A,pieces,mx);
else
A = sparse(ii,jj,A,pieces+n-1,mx);
end
% Don't use the sparse solver for small problems
if pieces < 20*n/log(1.7*n)
A = full(A);
end
% Solve
if isempty(constr)
% Solve Min norm(u*A-y)
u = lsqsolve(A,y,beta);
else
% Evaluate constraints
B = evalcon(base,constr,periodic);
% Solve constraints
[Z,u0] = solvecon(B,constr);
% Solve Min norm(u*A-y), subject to u*B = yc
y = y - u0*A;
A = Z*A;
v = lsqsolve(A,y,beta);
u = u0 + v*Z;
end
% Periodic expansion of solution
if periodic
jj = mod(0:pieces+n-2,pieces) + 1;
u = u(:,jj);
end
% Compute polynomial coefficients
ii = [repmat(1:pieces,1,n); ones(n-1,n*pieces)];
ii = cumsum(ii,1);
jj = repmat(1:n*pieces,n,1);
C = sparse(ii,jj,base.coefs,pieces+n-1,n*pieces);
coefs = u*C;
coefs = reshape(coefs,[],n);
% Make piecewise polynomial
pp = mkpp(breaks,coefs,dim);
%--------------------------------------------------------------------------
function [x,y,dim,breaks,n,periodic,beta,constr] = arguments(varargin)
%ARGUMENTS Lengthy input checking
% x Noisy data x-locations (1 x mx)
% y Noisy data y-values (prod(dim) x mx)
% dim Leading dimensions of y
% breaks Breaks (1 x (pieces+1))
% n Spline order
% periodic True if periodic boundary conditions
% beta Robust fitting parameter, no robust fitting if beta = 0
% constr Constraint structure
% constr.xc x-locations (1 x nx)
% constr.yc y-values (prod(dim) x nx)
% constr.cc Coefficients (?? x nx)
% Reshape x-data
x = varargin{1};
mx = numel(x);
x = reshape(x,1,mx);
% Remove trailing singleton dimensions from y
y = varargin{2};
dim = size(y);
while numel(dim) > 1 && dim(end) == 1
dim(end) = [];
end
my = dim(end);
% Leading dimensions of y
if numel(dim) > 1
dim(end) = [];
else
dim = 1;
end
% Reshape y-data
pdim = prod(dim);
y = reshape(y,pdim,my);
% Check data size
if mx ~= my
mess = 'Last dimension of array y must equal length of vector x.';
error('arguments:datasize',mess)
end
% Treat NaNs in x-data
inan = find(isnan(x));
if ~isempty(inan)
x(inan) = [];
y(:,inan) = [];
mess = 'All data points with NaN as x-location will be ignored.';
warning('arguments:nanx',mess)
end
% Treat NaNs in y-data
inan = find(any(isnan(y),1));
if ~isempty(inan)
x(inan) = [];
y(:,inan) = [];
mess = 'All data points with NaN in their y-value will be ignored.';
warning('arguments:nany',mess)
end
% Check number of data points
mx = numel(x);
if mx == 0
error('arguments:nodata','There must be at least one data point.')
end
% Sort data
if any(diff(x) < 0)
[x,isort] = sort(x);
y = y(:,isort);
end
% Breaks
if isscalar(varargin{3})
% Number of pieces
p = varargin{3};
if ~isreal(p) || ~isfinite(p) || p < 1 || fix(p) < p
mess = 'Argument #3 must be a vector or a positive integer.';
error('arguments:breaks1',mess)
end
if x(1) < x(end)
% Interpolate breaks linearly from x-data
dx = diff(x);
ibreaks = linspace(1,mx,p+1);
[junk,ibin] = histc(ibreaks,[0,2:mx-1,mx+1]); %#ok
breaks = x(ibin) + dx(ibin).*(ibreaks-ibin);
else
breaks = x(1) + linspace(0,1,p+1);
end
else
% Vector of breaks
breaks = reshape(varargin{3},1,[]);
if isempty(breaks) || min(breaks) == max(breaks)
mess = 'At least two unique breaks are required.';
error('arguments:breaks2',mess);
end
end
% Unique breaks
if any(diff(breaks) <= 0)
breaks = unique(breaks);
end
% Optional input defaults
n = 4; % Cubic splines
periodic = false; % No periodic boundaries
robust = false; % No robust fitting scheme
beta = 0.5; % Robust fitting parameter
constr = []; % No constraints
% Loop over optional arguments
for k = 4:nargin
a = varargin{k};
if ischar(a) && isscalar(a) && lower(a) == 'p'
% Periodic conditions
periodic = true;
elseif ischar(a) && isscalar(a) && lower(a) == 'r'
% Robust fitting scheme
robust = true;
elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && a < 1
% Robust fitting parameter
beta = a;
robust = true;
elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && fix(a) == a
% Spline order
n = a;
elseif isstruct(a) && isscalar(a)
% Constraint structure
constr = a;
else
error('arguments:nonsense','Failed to interpret argument #%d.',k)
end
end
% No robust fitting
if ~robust
beta = 0;
end
% Check exterior data
h = diff(breaks);
xlim1 = breaks(1) - 0.01*h(1);
xlim2 = breaks(end) + 0.01*h(end);
if x(1) < xlim1 || x(end) > xlim2
if periodic
% Move data inside domain
P = breaks(end) - breaks(1);
x = mod(x-breaks(1),P) + breaks(1);
% Sort
[x,isort] = sort(x);
y = y(:,isort);
else
mess = 'Some data points are outside the spline domain.';
warning('arguments:exteriordata',mess)
end
end
% Return
if isempty(constr)
return
end
% Unpack constraints
xc = [];
yc = [];
cc = [];
names = fieldnames(constr);
for k = 1:numel(names)
switch names{k}
case {'xc'}
xc = constr.xc;
case {'yc'}
yc = constr.yc;
case {'cc'}
cc = constr.cc;
otherwise
mess = 'Unknown field ''%s'' in constraint structure.';
warning('arguments:unknownfield',mess,names{k})
end
end
% Check xc
if isempty(xc)
mess = 'Constraints contains no x-locations.';
error('arguments:emptyxc',mess)
else
nx = numel(xc);
xc = reshape(xc,1,nx);
end
% Check yc
if isempty(yc)
% Zero array
yc = zeros(pdim,nx);
elseif numel(yc) == 1
% Constant array
yc = zeros(pdim,nx) + yc;
elseif numel(yc) ~= pdim*nx
% Malformed array
error('arguments:ycsize','Cannot reshape yc to size %dx%d.',pdim,nx)
else
% Reshape array
yc = reshape(yc,pdim,nx);
end
% Check cc
if isempty(cc)
cc = ones(size(xc));
elseif numel(size(cc)) ~= 2
error('arguments:ccsize1','Constraint coefficients cc must be 2D.')
elseif size(cc,2) ~= nx
mess = 'Last dimension of cc must equal length of xc.';
error('arguments:ccsize2',mess)
end
% Check high order derivatives
if size(cc,1) >= n
if any(any(cc(n:end,:)))
mess = 'Constraints involve derivatives of order %d or larger.';
error('arguments:difforder',mess,n-1)
end
cc = cc(1:n-1,:);
end
% Check exterior constraints
if min(xc) < xlim1 || max(xc) > xlim2
if periodic
% Move constraints inside domain
P = breaks(end) - breaks(1);
xc = mod(xc-breaks(1),P) + breaks(1);
else
mess = 'Some constraints are outside the spline domain.';
warning('arguments:exteriorconstr',mess)
end
end
% Pack constraints
constr = struct('xc',xc,'yc',yc,'cc',cc);
%--------------------------------------------------------------------------
function pp = splinebase(breaks,n)
%SPLINEBASE Generate B-spline base PP of order N for breaks BREAKS
breaks = breaks(:); % Breaks
breaks0 = breaks'; % Initial breaks
h = diff(breaks); % Spacing
pieces = numel(h); % Number of pieces
deg = n - 1; % Polynomial degree
% Extend breaks periodically
if deg > 0
if deg <= pieces
hcopy = h;
else
hcopy = repmat(h,ceil(deg/pieces),1);
end
% to the left
hl = hcopy(end:-1:end-deg+1);
bl = breaks(1) - cumsum(hl);
% and to the right
hr = hcopy(1:deg);
br = breaks(end) + cumsum(hr);
% Add breaks
breaks = [bl(deg:-1:1); breaks; br];
h = diff(breaks);
pieces = numel(h);
end
% Initiate polynomial coefficients
coefs = zeros(n*pieces,n);
coefs(1:n:end,1) = 1;
% Expand h
ii = [1:pieces; ones(deg,pieces)];
ii = cumsum(ii,1);
ii = min(ii,pieces);
H = h(ii(:));
% Recursive generation of B-splines
for k = 2:n
% Antiderivatives of splines
for j = 1:k-1
coefs(:,j) = coefs(:,j).*H/(k-j);
end
Q = sum(coefs,2);
Q = reshape(Q,n,pieces);
Q = cumsum(Q,1);
c0 = [zeros(1,pieces); Q(1:deg,:)];
coefs(:,k) = c0(:);
% Normalize antiderivatives by max value
fmax = repmat(Q(n,:),n,1);
fmax = fmax(:);
for j = 1:k
coefs(:,j) = coefs(:,j)./fmax;
end
% Diff of adjacent antiderivatives
coefs(1:end-deg,1:k) = coefs(1:end-deg,1:k) - coefs(n:end,1:k);
coefs(1:n:end,k) = 0;
end
% Scale coefficients
scale = ones(size(H));
for k = 1:n-1
scale = scale./H;
coefs(:,n-k) = scale.*coefs(:,n-k);
end
% Reduce number of pieces
pieces = pieces - 2*deg;
% Sort coefficients by interval number
ii = [n*(1:pieces); deg*ones(deg,pieces)];
ii = cumsum(ii,1);
coefs = coefs(ii(:),:);
% Make piecewise polynomial
pp = mkpp(breaks0,coefs,n);
%--------------------------------------------------------------------------
function B = evalcon(base,constr,periodic)
%EVALCON Evaluate linear constraints
% Unpack structures
breaks = base.breaks;
pieces = base.pieces;
n = base.order;
xc = constr.xc;
cc = constr.cc;
% Bin data
[junk,ibin] = histc(xc,[-inf,breaks(2:end-1),inf]); %#ok
% Evaluate constraints
nx = numel(xc);
B0 = zeros(n,nx);
for k = 1:size(cc,1)
if any(cc(k,:))
B0 = B0 + repmat(cc(k,:),n,1).*ppval(base,xc);
end
% Differentiate base
coefs = base.coefs(:,1:n-k);
for j = 1:n-k-1
coefs(:,j) = (n-k-j+1)*coefs(:,j);
end
base.coefs = coefs;
base.order = n-k;
end
% Sparse output
ii = [ibin; ones(n-1,nx)];
ii = cumsum(ii,1);
jj = repmat(1:nx,n,1);
if periodic
ii = mod(ii-1,pieces) + 1;
B = sparse(ii,jj,B0,pieces,nx);
else
B = sparse(ii,jj,B0,pieces+n-1,nx);
end
%--------------------------------------------------------------------------
function [Z,u0] = solvecon(B,constr)
%SOLVECON Find a particular solution u0 and null space Z (Z*B = 0)
% for constraint equation u*B = yc.
yc = constr.yc;
tol = 1000*eps;
% Remove blank rows
ii = any(B,2);
B2 = full(B(ii,:));
% Null space of B2
if isempty(B2)
Z2 = [];
else
% QR decomposition with column permutation
[Q,R,dummy] = qr(B2); %#ok
R = abs(R);
jj = all(R < R(1)*tol, 2);
Z2 = Q(:,jj)';
end
% Sizes
[m,ncon] = size(B);
m2 = size(B2,1);
nz = size(Z2,1);
% Sparse null space of B
Z = sparse(nz+1:nz+m-m2,find(~ii),1,nz+m-m2,m);
Z(1:nz,ii) = Z2;
% Warning rank deficient
if nz + ncon > m2
mess = 'Rank deficient constraints, rank = %d.';
warning('solvecon:deficient',mess,m2-nz);
end
% Particular solution
u0 = zeros(size(yc,1),m);
if any(yc(:))
% Non-homogeneous case
u0(:,ii) = yc/B2;
% Check solution
if norm(u0*B - yc,'fro') > norm(yc,'fro')*tol
mess = 'Inconsistent constraints. No solution within tolerance.';
error('solvecon:inconsistent',mess)
end
end
%--------------------------------------------------------------------------
function u = lsqsolve(A,y,beta)
%LSQSOLVE Solve Min norm(u*A-y)
% Avoid sparse-complex limitations
if issparse(A) && ~isreal(y)
A = full(A);
end
% Solution
u = y/A;
% Robust fitting
if beta > 0
[m,n] = size(y);
alpha = 0.5*beta/(1-beta)/m;
for k = 1:3
% Residual
r = u*A - y;
rr = r.*conj(r);
rrmean = sum(rr,2)/n;
rrmean(~rrmean) = 1;
rrhat = (alpha./rrmean)'*rr;
% Weights
w = exp(-rrhat);
spw = spdiags(w',0,n,n);
% Solve weighted problem
u = (y*spw)/(A*spw);
end
end
%-----------------------------------------
function qq = ppdiff(pp,j)
%PPDIFF Differentiate piecewise polynomial.
% QQ = PPDIFF(PP,J) returns the J:th derivative of a piecewise
% polynomial PP. PP must be on the form evaluated by PPVAL. QQ is a
% piecewise polynomial on the same form. Default value for J is 1.
%
% Example:
% x = linspace(-pi,pi,9);
% y = sin(x);
% pp = spline(x,y);
% qq = ppdiff(pp);
% xx = linspace(-pi,pi,201);
% plot(xx,cos(xx),'b',xx,ppval(qq,xx),'r')
%
% See also PPVAL, SPLINE, SPLINEFIT, PPINT
% Author: Jonas Lundgren <splinefit@gmail.com> 2009
if nargin < 1, help ppdiff, return, end
if nargin < 2, j = 1; end
% Check diff order
if ~isreal(j) || mod(j,1) || j < 0
msgid = 'PPDIFF:DiffOrder';
message = 'Order of derivative must be a non-negative integer!';
error(msgid,message)
end
% Get coefficients
coefs = pp.coefs;
[m n] = size(coefs);
if j == 0
% Do nothing
elseif j < n
% Derivative of order J
D = [n-j:-1:1; ones(j-1,n-j)];
D = cumsum(D,1);
D = prod(D,1);
coefs = coefs(:,1:n-j);
for k = 1:n-j
coefs(:,k) = D(k)*coefs(:,k);
end
else
% Derivative kills PP
coefs = zeros(m,1);
end
% Set output
qq = pp;
qq.coefs = coefs;
qq.order = size(coefs,2);
%-----------------------------------------
function output = ppint(pp,a,b)
%PPINT Integrate piecewise polynomial.
% QQ = PPINT(PP,A) returns the indefinite integral from A to X of a
% piecewise polynomial PP. PP must be on the form evaluated by PPVAL.
% QQ is a piecewise polynomial on the same form. Default value for A is
% the leftmost break of PP.
%
% I = PPINT(PP,A,B) returns the definite integral from A to B.
%
% Example:
% x = linspace(-pi,pi,7);
% y = sin(x);
% pp = spline(x,y);
% I = ppint(pp,0,pi)
%
% qq = ppint(pp,pi/2);
% xx = linspace(-pi,pi,201);
% plot(xx,-cos(xx),xx,ppval(qq,xx),'r')
%
% See also PPVAL, SPLINE, SPLINEFIT, PPDIFF
% Author: Jonas Lundgren <splinefit@gmail.com> 2009
if nargin < 1, help ppint, return, end
if nargin < 2, a = pp.breaks(1); end
% Get coefficients and breaks
coefs = pp.coefs;
[m n] = size(coefs);
xb = pp.breaks;
pdim = prod(pp.dim);
% Interval lengths
hb = diff(xb);
hb = repmat(hb,pdim,1);
hb = hb(:);
% Integration
coefs(:,1) = coefs(:,1)/n;
y = coefs(:,1).*hb;
for k = 2:n
coefs(:,k) = coefs(:,k)/(n-k+1);
y = (y + coefs(:,k)).*hb;
end
y = reshape(y,pdim,[]);
I = cumsum(y,2);
I = I(:);
coefs(:,n+1) = [zeros(pdim,1); I(1:m-pdim)];
% Set preliminary indefinite integral
qq = pp;
qq.coefs = coefs;
qq.order = n+1;
% Set output
if nargin < 3
% Indefinite integral from a to x
if a ~= xb(1)
I0 = ppval(qq,a);
I0 = I0(:);
I0 = repmat(I0,m/pdim,1);
qq.coefs(:,n+1) = qq.coefs(:,n+1) - I0;
end
output = qq;
else
% Definite integral from a to b
output = ppval(qq,b) - ppval(qq,a);
end
%-----------------------------------------
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/Matlab/wobble/wobbleCorrectSimBead.m | .m | 868 | 29 | function wobbleCorrectSimBead(xnm,ynm,frame,gt,zmin,zstep,zmax,roiRadius,fname)
nBead = size(gt,1);
for ii = 1:nBead
beadPos = gt(ii,:);
ROInm(ii,1:2) = beadPos-roiRadius;%xmin ymin
ROInm(ii,3:4) = 2*roiRadius;%width height
end
zSlice = zmin:zstep:zmax;
%frameIsOneIndexed = ~sum(frame==0) > 0;%should detect it automatically
%if ~frameIsOneIndexed
% frame = frame+1;%have to account for possilbe zero-indexing or everthing will get screwed up
%end
znm = zSlice(frame)';
[znm, indSort] = sort(znm);
xnm = xnm(indSort);
ynm = ynm(indSort);
wobbleMatrix = wobbleCalibration(xnm, ynm, znm, nBead, 'ROI', ROInm, 'Zfit', zSlice, 'NumSplineBreak', 10,...
'GT', gt);
[~, indCorr] = unique(wobbleMatrix(:,1));
wobbleMatrixUnique = wobbleMatrix(indCorr,[2,3,1]);
%save in csv file, units : nm, column order : X Y Z
csvwrite(fname, wobbleMatrixUnique);
| MATLAB |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/SpinnerDouble.java | .java | 3,557 | 119 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
/**
* This class extends the generic JSpinner of Java for a
* specific JSpinner for double. It handles double type.
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class SpinnerDouble extends JSpinner {
private SpinnerNumberModel model;
private double defValue;
private double minValue;
private double maxValue;
private double incValue;
/**
* Constructor.
*/
public SpinnerDouble(double defValue, double minValue, double maxValue, double incValue) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Double def = new Double(defValue);
Double min = new Double(minValue);
Double max = new Double(maxValue);
Double inc = new Double(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Set the minimal and the maximal limit.
*/
public void setLimit(double minValue, double maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
double value = get();
Double min = new Double(minValue);
Double max = new Double(maxValue);
Double inc = new Double(incValue);
defValue = (value > maxValue ? maxValue : (value < minValue ? minValue : value));
Double def = new Double(defValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Set the incremental step.
*/
public void setIncrement(double incValue) {
this.incValue = incValue;
Double def = (Double)getModel().getValue();
Double min = new Double(minValue);
Double max = new Double(maxValue);
Double inc = new Double(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Returns the incremental step.
*/
public double getIncrement() {
return incValue;
}
/**
* Set the value in the JSpinner with clipping in the range [min..max].
*/
public void set(double value) {
value = (value > maxValue ? maxValue : (value < minValue ? minValue : value));
model.setValue(value);
}
/**
* Return the value with clipping the value in the range [min..max].
*/
public double get() {
if (model.getValue() instanceof Integer) {
Integer i = (Integer)model.getValue();
double ii = i.intValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
else if (model.getValue() instanceof Double) {
Double i = (Double)model.getValue();
double ii = i.doubleValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
else if (model.getValue() instanceof Float) {
Float i = (Float)model.getValue();
double ii = i.floatValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
return 0.0;
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/Settings.java | .java | 12,943 | 448 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Properties;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.Timer;
/**
* This class allows to store and load key-associated values in a text file.
* The class has methods to load and store single value linked to a string
* key describing the value. Futhermore, this class has methods to record
* a GUI component to a specified key. By this way this class allows to
* load and store all recorded items.
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class Settings {
private String filename;
private String project;
private ArrayList<Item> items;
private Properties props;
/**
* Constructors a Settings abject for a given project name and a given filename.
*
* @param project a string describing the project
* @param filename a string give the full name of the file, including the path
*/
public Settings(String project, String filename) {
this.filename = filename;
this.project = project;
items = new ArrayList<Item>();
props = new Properties();
}
/**
* Records a JTextField component to store/load automatically.
*
* @param key a string describing the value
* @param component the component to record
* @param defaultValue the default value
*/
public void record(String key, JTextField component, String defaultValue) {
Item item = new Item(key, component, defaultValue);
items.add(item);
}
/**
* Records a JComboBox component to store/load automatically.
*
* @param key a string describing the value
* @param component the component to record
* @param defaultValue the default value
*/
public void record(String key, JComboBox component, String defaultValue) {
Item item = new Item(key, component, defaultValue);
items.add(item);
}
/**
* Records a JSpinner component to store/load automatically.
*
* @param key a string describing the value
* @param component the component to record
* @param defaultValue the default value
*/
public void record(String key, JSpinner component, String defaultValue) {
Item item = new Item(key, component, defaultValue);
items.add(item);
}
/**
* Records a JToggleButton component to store/load automatically.
*
* @param key a string describing the value
* @param component the component to record
* @param defaultValue the default value
*/
public void record(String key, JToggleButton component, boolean defaultValue) {
Item item = new Item(key, component, (defaultValue ? "on" : "off"));
items.add(item);
}
/**
* Records a JCheckBox component to store/load automatically.
*
* @param key a string describing the value
* @param component the component to record
* @param defaultValue the default value
*/
public void record(String key, JCheckBox component, boolean defaultValue) {
Item item = new Item(key, component, (defaultValue ? "on" : "off"));
items.add(item);
}
/**
* Records a JSlider component to store/load automatically.
*
* @param key a int value
* @param component the component to record
* @param defaultValue the default value
*/
public void record(String key, JSlider component, String defaultValue) {
Item item = new Item(key, component, defaultValue);
items.add(item);
}
/**
* Load an individual double value given a specified key
*
* @param key a string describing the value
* @param defaultValue the default value
* @return the value get from the file
*/
public String loadValue(String key, String defaultValue) {
String s = "";
try {
FileInputStream in = new FileInputStream(filename);
props.load(in);
s = props.getProperty(key, "" + defaultValue);
}
catch(Exception e) {
s = defaultValue;
}
return s;
}
/**
* Load an individual double value given a specified key
*
* @param key a string describing the value
* @param defaultValue the default value
* @return the value get from the file
*/
public double loadValue(String key, double defaultValue) {
double d = 0;
try {
FileInputStream in = new FileInputStream(filename);
props.load(in);
String value = props.getProperty(key, "" + defaultValue);
d = (new Double(value)).doubleValue();
}
catch(Exception e) {
d = defaultValue;
}
return d;
}
/**
* Load an individual integer value given a specified key
*
* @param key a string describing the value
* @param defaultValue the default value
* @return the value get from the file
*/
public int loadValue(String key, int defaultValue) {
int i = 0;
try {
FileInputStream in = new FileInputStream(filename);
props.load(in);
String value = props.getProperty(key, "" + defaultValue);
i = (new Integer(value)).intValue();
}
catch(Exception e) {
i = defaultValue;
}
return i;
}
/**
* Load an individual boolean value given a specified key
*
* @param key a string describing the value
* @param defaultValue the default value
* @return the value get from the file
*/
public boolean loadValue(String key, boolean defaultValue) {
boolean b = false;
try {
FileInputStream in = new FileInputStream(filename);
props.load(in);
String value = props.getProperty(key, "" + defaultValue);
b = (new Boolean(value)).booleanValue();
}
catch(Exception e) {
b = defaultValue;
}
return b;
}
/**
* Store an individual double value given a specified key
*
* @param key a string describing the value
* @param value the value to store
*/
public void storeValue(String key, String value) {
props.setProperty(key, value);
try {
FileOutputStream out = new FileOutputStream(filename);
props.store(out, project);
}
catch(Exception e) {
new Msg(project, "Impossible to store settings in (" + filename + ")");
}
}
/**
* Store an individual double value given a specified key
*
* @param key a string describing the value
* @param value the value to store
*/
public void storeValue(String key, double value) {
props.setProperty(key, ""+value);
try {
FileOutputStream out = new FileOutputStream(filename);
props.store(out, project);
}
catch(Exception e) {
new Msg(project, "Impossible to store settings in (" + filename + ")");
}
}
/**
* Store an individual integer value given a specified key
*
* @param key a string describing the value
* @param value the value to store
*/
public void storeValue(String key, int value) {
props.setProperty(key, ""+value);
try {
FileOutputStream out = new FileOutputStream(filename);
props.store(out, project);
}
catch(Exception e) {
new Msg(project, "Impossible to store settings in (" + filename + ")");
}
}
/**
* Store an individual boolean value given a specified key
*
* @param key a string describing the value
* @param value the value to store
*/
public void storeValue(String key, boolean value) {
props.setProperty(key, ""+value);
try {
FileOutputStream out = new FileOutputStream(filename);
props.store(out, project);
}
catch(Exception e) {
new Msg(project, "Impossible to store settings in (" + filename + ")");
}
}
/**
* Load all recorded values.
*/
public void loadRecordedItems() {
loadRecordedItems(filename);
}
/**
* Load all recorded values from a specified filename.
*/
public void loadRecordedItems(String fname) {
try {
FileInputStream in = new FileInputStream(fname);
props.load(in);
}
catch(Exception e) {
new Msg(project, "Loading default value. No settings file (" + fname + ")");
}
for(int i=0; i<items.size(); i++) {
Item item = (Item)items.get(i);
String value = props.getProperty(item.key, item.defaultValue);
if (item.component instanceof JTextField) {
((JTextField)item.component).setText(value);
}
else if (item.component instanceof JComboBox) {
((JComboBox)item.component).setSelectedItem(value);
}
else if (item.component instanceof JCheckBox) {
((JCheckBox)item.component).setSelected(value.equals("on") ? true : false);
}
else if (item.component instanceof JToggleButton) {
((JToggleButton)item.component).setSelected(value.equals("on") ? true : false);
}
else if (item.component instanceof JSpinner) {
((JSpinner)item.component).setValue((new Double(value)).doubleValue());
}
else if (item.component instanceof JSlider) {
((JSlider)item.component).setValue((new Integer(value)).intValue());
}
}
}
/**
* Store all recorded values.
*/
public void storeRecordedItems() {
storeRecordedItems(filename);
}
/**
* Store all recorded values into a specified filename
*/
public void storeRecordedItems(String fname) {
for(int i=0; i<items.size(); i++) {
Item item = (Item)items.get(i);
if (item.component instanceof JTextField) {
String value = ((JTextField)item.component).getText();
props.setProperty(item.key, value);
}
else if (item.component instanceof JComboBox) {
String value = (String)((JComboBox)item.component).getSelectedItem();
props.setProperty(item.key, value);
}
else if (item.component instanceof JCheckBox) {
String value = (((JCheckBox)item.component).isSelected() ? "on" : "off");
props.setProperty(item.key, value);
}
else if (item.component instanceof JToggleButton) {
String value = (((JToggleButton)item.component).isSelected() ? "on" : "off");
props.setProperty(item.key, value);
}
else if (item.component instanceof JSpinner) {
String value = ""+((JSpinner)item.component).getValue();
props.setProperty(item.key, value);
}
else if (item.component instanceof JSlider) {
String value = ""+((JSlider)item.component).getValue();
props.setProperty(item.key, value);
}
}
try {
FileOutputStream out = new FileOutputStream(fname);
props.store(out, project);
}
catch(Exception e) {
new Msg(project, "Impossible to store settings in (" + fname + ")");
}
}
/**
* Private class to store one component and its key.
*/
private class Item {
public Object component;
public String defaultValue;
public String key;
public Item(String key, Object component, String defaultValue) {
this.component = component;
this.defaultValue = defaultValue;
this.key = key;
}
}
/**
* Private class to display an alert message when the file is not found.
*/
private class Msg extends JFrame {
public Msg(String project, String msg) {
super(project);
GridBagLayout layout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
Container contentPane = getContentPane();
contentPane.setLayout(layout);
constraints.weightx = 0.0;
constraints.weighty = 1.0;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.insets = new Insets(10, 10, 10, 10);
constraints.anchor = GridBagConstraints.CENTER;
JLabel newLabel = new JLabel(msg);
layout.setConstraints(newLabel,constraints);
contentPane.add(newLabel);
setResizable(false);
pack();
setVisible(true);
Dimension dim = getToolkit().getScreenSize();
Rectangle abounds = getBounds();
setLocation((dim.width - abounds.width) / 2, (dim.height - abounds.height) / 2);
Timer timer = new Timer(1000, new DelayListener(this));
timer.start();
}
}
/**
* Private class to dispose the message after 1 second.
*/
private class DelayListener implements ActionListener {
private Msg msg;
public DelayListener(Msg msg) {
this.msg = msg;
}
public void actionPerformed(ActionEvent evt) {
msg.dispose();
}
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/Chrono.java | .java | 1,854 | 64 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import java.text.DecimalFormat;
/**
* This class provides static methods to measures the elapsed time.
* It is a equivalent to the function tic and toc of Matlab.
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class Chrono {
static private double chrono = 0;
/**
* Register the current time.
*/
public static void tic() {
chrono = System.currentTimeMillis();
}
/**
* Returns a string that indicates the elapsed time since the last tic() call.
*/
public static String toc() {
return toc("");
}
/**
* Returns a string that indicates the elapsed time since the last tic() call.
*
* @param msg message to print
*/
public static String toc(String msg) {
double te = System.currentTimeMillis()-chrono;
String s = msg + " ";
DecimalFormat df = new DecimalFormat("####.##");
if (te < 3000.0)
return s + df.format(te) + " ms";
te /= 1000;
if (te < 600.1)
return s + df.format(te) + " s";
te /= 60;
if (te < 240.1)
return s + df.format(te) + " min.";
te /= 24;
return s + df.format(te) + " h.";
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/GridPanel.java | .java | 4,211 | 169 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* This class extends the JToolbar to create grid panel
* given the possibility to place Java compoments in
* an organized manner in the dialog box.
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class GridPanel extends JPanel {
private GridBagLayout layout = new GridBagLayout();
private GridBagConstraints constraint = new GridBagConstraints();
private int defaultSpace = 3;
/**
* Constructor.
*/
public GridPanel() {
super();
setLayout(layout);
setBorder(BorderFactory.createEtchedBorder());
}
/**
* Constructor.
*/
public GridPanel(int defaultSpace) {
super();
setLayout(layout);
this.defaultSpace = defaultSpace;
setBorder(BorderFactory.createEtchedBorder());
}
/**
* Constructor.
*/
public GridPanel(boolean border) {
super();
setLayout(layout);
if (border) {
setBorder(BorderFactory.createEtchedBorder());
}
}
/**
* Constructor.
*/
public GridPanel(String title) {
super();
setLayout(layout);
setBorder(BorderFactory.createTitledBorder(title));
}
/**
* Constructor.
*/
public GridPanel(boolean border, int defaultSpace) {
super();
setLayout(layout);
this.defaultSpace = defaultSpace;
if (border) {
setBorder(BorderFactory.createEtchedBorder());
}
}
/**
* Constructor.
*/
public GridPanel(String title, int defaultSpace) {
super();
setLayout(layout);
this.defaultSpace = defaultSpace;
setBorder(BorderFactory.createTitledBorder(title));
}
/**
* Specify the defaultSpace.
*/
public void setSpace(int defaultSpace) {
this.defaultSpace = defaultSpace;
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, String label) {
place(row, col, 1, 1, defaultSpace, new JLabel(label));
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, int space, String label) {
place(row, col, 1, 1, space, new JLabel(label));
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, int width, int height, String label) {
place(row, col, width, height, defaultSpace, new JLabel(label));
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, JComponent comp) {
place(row, col, 1, 1, defaultSpace, comp);
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, int space, JComponent comp) {
place(row, col, 1, 1, space, comp);
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, int width, int height, JComponent comp) {
place(row, col, width, height, defaultSpace, comp);
}
/**
* Place a component in the northwest of the cell.
*/
public void place(int row, int col, int width, int height, int space, JComponent comp) {
constraint.gridx = col;
constraint.gridy = row;
constraint.gridwidth = width;
constraint.gridheight = height;
constraint.anchor = GridBagConstraints.NORTHWEST;
constraint.insets = new Insets(space, space, space, space);
constraint.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(comp, constraint);
add(comp);
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/SpinnerFloat.java | .java | 3,532 | 121 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
/**
* This class extends the generic JSpinner of Java for a
* specific JSpinner for float. It handles float type.
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class SpinnerFloat extends JSpinner {
private SpinnerNumberModel model;
private float defValue;
private float minValue;
private float maxValue;
private float incValue;
/**
* Constructor.
*/
public SpinnerFloat(float defValue, float minValue, float maxValue, float incValue) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Float def = new Float(defValue);
Float min = new Float(minValue);
Float max = new Float(maxValue);
Float inc = new Float(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Set the minimal and the maximal limit.
*/
public void setLimit(float minValue, float maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
float value = get();
Float min = new Float(minValue);
Float max = new Float(maxValue);
Float inc = new Float(incValue);
defValue = (value > maxValue ? maxValue : (value < minValue ? minValue : value));
Float def = new Float(defValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Set the incremental step.
*/
public void setIncrement(float incValue) {
this.incValue = incValue;
Float def = (Float)getModel().getValue();
Float min = new Float(minValue);
Float max = new Float(maxValue);
Float inc = new Float(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Returns the incremental step.
*/
public float getIncrement() {
return incValue;
}
/**
* Set the value in the JSpinner with clipping in the range [min..max].
*/
public void set(float value) {
value = (value > maxValue ? maxValue : (value < minValue ? minValue : value));
model.setValue(value);
}
/**
* Return the value without clipping the value in the range [min..max].
*/
public float get() {
if (model.getValue() instanceof Integer) {
Integer i = (Integer)model.getValue();
float ii = (float)i.intValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
else if (model.getValue() instanceof Double) {
Double i = (Double)model.getValue();
float ii = (float)i.doubleValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
else if (model.getValue() instanceof Float) {
Float i = (Float)model.getValue();
float ii = i.floatValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
return 0f;
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/SpinnerInteger.java | .java | 3,538 | 119 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
/**
* This class extends the generic JSpinner of Java for a
* specific JSpinner for integer. It handles int type.
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class SpinnerInteger extends JSpinner {
private SpinnerNumberModel model;
private int defValue;
private int minValue;
private int maxValue;
private int incValue;
/**
* Constructor.
*/
public SpinnerInteger(int defValue, int minValue, int maxValue, int incValue) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Integer def = new Integer(defValue);
Integer min = new Integer(minValue);
Integer max = new Integer(maxValue);
Integer inc = new Integer(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Set the minimal and the maximal limit.
*/
public void setLimit(int minValue, int maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
int value = get();
Integer min = new Integer(minValue);
Integer max = new Integer(maxValue);
Integer inc = new Integer(incValue);
defValue = (value > maxValue ? maxValue : (value < minValue ? minValue : value));
Integer def = new Integer(defValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Set the incremental step.
*/
public void setIncrement(int incValue) {
this.incValue = incValue;
Integer def = (Integer)getModel().getValue();
Integer min = new Integer(minValue);
Integer max = new Integer(maxValue);
Integer inc = new Integer(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
}
/**
* Returns the incremental step.
*/
public int getIncrement() {
return incValue;
}
/**
* Set the value in the JSpinner with clipping in the range [min..max].
*/
public void set(int value) {
value = (value > maxValue ? maxValue : (value < minValue ? minValue : value));
model.setValue(value);
}
/**
* Return the value without clipping the value in the range [min..max].
*/
public int get() {
if (model.getValue() instanceof Integer) {
Integer i = (Integer)model.getValue();
int ii = i.intValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
else if (model.getValue() instanceof Double) {
Double i = (Double)model.getValue();
int ii = (int)i.doubleValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
else if (model.getValue() instanceof Float) {
Float i = (Float)model.getValue();
int ii = (int)i.floatValue();
return (ii > maxValue ? maxValue : (ii < minValue ? minValue : ii));
}
return 0;
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/additionaluserinterface/WalkBar.java | .java | 10,257 | 323 | //=========================================================================================
//
// Project: AdditionalUserInterface - Providing GUI for ImageJ plugin
//
// Author : Daniel Sage, Biomedical Imaging Group (BIG), http://bigwww.epfl.ch/sage/
//
// Organization: Ecole Polytechnique Federale de Lausanne (EPFL), Lausanne, Switzerland
//
// Conditions of use: You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package additionaluserinterface;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.text.DefaultCaret;
/**
* This class extends the JToolbar of Java to create a status bar
* including some of the following component ProgressBar, Help Button
* About Button and Close Button
*
* @author Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland.
*
*/
public class WalkBar extends JToolBar implements ActionListener {
private JProgressBar progress = new JProgressBar();
private JButton bnHelp = new JButton("Help");
private JButton bnAbout = new JButton("About");
private JButton bnClose = new JButton("Close");
private String about[] = {"About", "Version", "Description", "Author", "Biomedical Image Group", "2008", "http://bigwww.epfl.ch"};
private String help;
private double chrono;
private int xSizeAbout = 400;
private int ySizeAbout = 400;
private int xSizeHelp = 400;
private int ySizeHelp = 400;
/**
* Constructor.
*/
public WalkBar(String initialMessage, boolean isAbout, boolean isHelp, boolean isClose) {
super("Walk Bar");
build(initialMessage, isAbout, isHelp, isClose, 100);
}
public WalkBar(String initialMessage, boolean isAbout, boolean isHelp, boolean isClose, int size) {
super("Walk Bar");
build(initialMessage, isAbout, isHelp, isClose, size);
}
private void build(String initialMessage, boolean isAbout, boolean isHelp, boolean isClose, int size) {
if (isAbout)
add(bnAbout);
if (isHelp)
add(bnHelp);
addSeparator();
add(progress);
addSeparator();
if (isClose)
add(bnClose);
progress.setStringPainted(true);
progress.setString(initialMessage);
progress.setFont(new Font("Arial", Font.PLAIN, 10));
progress.setMinimum(0);
progress.setMaximum(100);
progress.setPreferredSize(new Dimension(size, 20));
bnAbout.addActionListener(this);
bnHelp.addActionListener(this);
setFloatable(false);
setRollover(true);
setBorderPainted(false);
chrono = System.currentTimeMillis();
}
/**
* Implements the actionPerformed for the ActionListener.
*/
public synchronized void actionPerformed(ActionEvent e) {
if (e.getSource() == bnHelp) {
showHelp();
}
else if (e.getSource() == bnAbout) {
showAbout();
}
else if (e.getSource() == bnClose) {
}
}
/**
* Return a reference to the Close button.
*/
public JButton getButtonClose() {
return bnClose;
}
/**
* Set a value in the progress bar.
*/
public void setValue(int value) {
progress.setValue(value);
}
/**
* Set a message in the progress bar.
*/
public void setMessage(String msg) {
progress.setString(msg);
}
/**
* Set a value and a message in the progress bar.
*/
public void progress(String msg, int value) {
progress.setValue(value);
double elapsedTime = System.currentTimeMillis() - chrono;
String t = " [" + (elapsedTime > 3000 ? Math.round(elapsedTime/10)/100.0 + "s." : elapsedTime + "ms") + "]";
progress.setString(msg + t);
}
/**
* Set a value and a message in the progress bar.
*/
public void progress(String msg, double value) {
progress(msg, (int)Math.round(value));
}
/**
* Set to 0 the progress bar.
*/
public void reset() {
chrono = System.currentTimeMillis();
progress.setValue(0);
progress.setString("Starting ...");
}
/**
* Set to 100 the progress bar.
*/
public void finish() {
progress("Terminated", 100);
}
/**
* Set to 100 the progress bar with an additional message.
*/
public void finish(String msg) {
progress(msg, 100);
}
/**
* Specify the content of the About window.
*/
public void fillAbout(String name, String version, String description, String author, String organisation, String date, String info) {
this.about[0] = name;
this.about[1] = version;
this.about[2] = description;
this.about[3] = author;
this.about[4] = organisation;
this.about[5] = date;
this.about[6] = info;
}
/**
* Specify the content of the Help window.
*/
public void fillHelp(String help) {
this.help = help;
}
/**
* Show the content of the About window.
*/
public void showAbout() {
final JFrame frame = new JFrame("About "+ about[0]);
JEditorPane pane = new JEditorPane();
pane.setEditable(false);
pane.setContentType("text/html; charset=ISO-8859-1");
pane.setText("<html><head><title>" + about[0] + "</title>" + getStyle() + "</head><body>" +
(about[0] == "" ? "" : "<p class=\"name\">" + about[0] + "</p>") + // Name
(about[1] == "" ? "" : "<p class=\"vers\">" + about[1] + "</p>") + // Version
(about[2] == "" ? "" : "<p class=\"desc\">" + about[2] + "</p><hr>") + // Description
(about[3] == "" ? "" : "<p class=\"auth\">" + about[3] + "</p>") + //author
(about[4] == "" ? "" : "<p class=\"orga\">" + about[4] + "</p>") +
(about[5] == "" ? "" : "<p class=\"date\">" + about[5] + "</p>") +
(about[6] == "" ? "" : "<p class=\"more\">" + about[6] + "</p>") +
"</html>"
);
final JButton bnClose = new JButton("Close");
bnClose.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
pane.setCaret(new DefaultCaret());
JScrollPane scrollPane = new JScrollPane(pane);
//helpScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(xSizeAbout, ySizeAbout));
frame.getContentPane().add(scrollPane, BorderLayout.NORTH);
frame.getContentPane().add(bnClose, BorderLayout.CENTER);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
center(frame);
}
/**
* Show the content of the Help window of a given size.
*/
public void showHelp() {
final JFrame frame = new JFrame("Help "+ about[0]);
JEditorPane pane = new JEditorPane();
pane.setEditable(false);
pane.setContentType("text/html; charset=ISO-8859-1");
pane.setText("<html><head><title>" + about[0] + "</title>" + getStyle() + "</head><body>" +
(about[0] == "" ? "" : "<p class=\"name\">" + about[0] + "</p>") + // Name
(about[1] == "" ? "" : "<p class=\"vers\">" + about[1] + "</p>") + // Version
(about[2] == "" ? "" : "<p class=\"desc\">" + about[2] + "</p>") + // Description
"<hr><p class=\"help\">" + help + "</p>" +
"</html>"
);
final JButton bnClose = new JButton("Close");
bnClose.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
pane.setCaret(new DefaultCaret());
JScrollPane scrollPane = new JScrollPane(pane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(xSizeHelp, ySizeHelp));
frame.setPreferredSize(new Dimension(xSizeHelp, ySizeHelp));
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.getContentPane().add(bnClose, BorderLayout.SOUTH);
frame.setVisible(true);
frame.pack();
center(frame);
}
/*
* Place the window in the center of the screen.
*/
private void center(Window w) {
Dimension screenSize = new Dimension(0, 0);
boolean isWin = System.getProperty("os.name").startsWith("Windows");
if (isWin) { // GraphicsEnvironment.getConfigurations is *very* slow on Windows
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
}
if (GraphicsEnvironment.isHeadless())
screenSize = new Dimension(0, 0);
else {
// Can't use Toolkit.getScreenSize() on Linux because it returns
// size of all displays rather than just the primary display.
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
GraphicsConfiguration[] gc = gd[0].getConfigurations();
Rectangle bounds = gc[0].getBounds();
if (bounds.x==0&&bounds.y==0)
screenSize = new Dimension(bounds.width, bounds.height);
else
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
}
Dimension window = w.getSize();
if (window.width==0)
return;
int left = screenSize.width/2-window.width/2;
int top = (screenSize.height-window.height)/4;
if (top<0) top = 0;
w.setLocation(left, top);
}
/*
* Defines the CSS style for the help and about window.
*/
private String getStyle() {
return
"<style type=text/css>" +
"body {backgroud-color:#222277}" +
"hr {width:80% color:#333366; padding-top:7px }" +
"p, li {margin-left:10px;margin-right:10px; color:#000000; font-size:1em; font-family:Verdana,Helvetica,Arial,Geneva,Swiss,SunSans-Regular,sans-serif}" +
"p.name {color:#ffffff; font-size:1.2em; font-weight: bold; background-color: #333366; text-align:center;}" +
"p.vers {color:#333333; text-align:center;}" +
"p.desc {color:#333333; font-weight: bold; text-align:center;}" +
"p.auth {color:#333333; font-style: italic; text-align:center;}" +
"p.orga {color:#333333; text-align:center;}" +
"p.date {color:#333333; text-align:center;}" +
"p.more {color:#333333; text-align:center;}" +
"p.help {color:#000000; text-align:left;}" +
"</style>";
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/smlms/Description.java | .java | 1,854 | 64 | // =========================================================================================
//
// Single-Molecule Localization Microscopy Challenge 2016
// http://bigwww.epfl.ch/smlm/
//
// Author:
// Daniel Sage, http://bigwww.epfl.ch/sage/
// Biomedical Imaging Group (BIG)
// Ecole Polytechnique Federale de Lausanne (EPFL), CH-1015 Lausanne,
// Switzerland
//
// Reference:
// D. Sage, H. Kirshner, T. Pengo, N. Stuurman, J. Min, S. Manley, M. Unser
// Quantitative Evaluation of Software Packages for Single-Molecule Localization
// Microscopy
// Nature Methods 12, August 2015.
//
// Conditions of use:
// You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to
// include a
// citation or acknowledgment whenever you present or publish results that are
// based on it.
//
// =========================================================================================
package smlms;
public class Description {
public String name = "noname";
public double pixelsize = 100;
public double zstep = 10;
public double shiftX = 0;
public double shiftY = 0;
public double shiftZ = 0;
public double shiftFrame = 0;
public int colX = 2;
public int colY = 3;
public int colZ = 4;
public int colFrame = 1;
public int colIntensity = 5;
public int firstRow = 0;
public Description() {
}
public Description(String name, int colX, int colY, int colZ, int colFrame, int colIntensity, double pixelsize, double zstep) {
this.name = name;
this.colX = colX;
this.colY = colY;
this.colZ = colZ;
this.colFrame = colFrame;
this.colIntensity = colIntensity;
this.pixelsize = pixelsize;
this.zstep = zstep;
}
public void shift(double shiftX, double shiftY) {
this.shiftX = shiftX;
this.shiftY = shiftY;
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/smlms/CompareLocalization3DDialog.java | .java | 19,031 | 455 | //=========================================================================================
//
// Single-Molecule Localization Microscopy Challenge 2016
// http://bigwww.epfl.ch/smlm/
//
// Author:
// Daniel Sage, http://bigwww.epfl.ch/sage/
// Biomedical Imaging Group (BIG)
// Ecole Polytechnique Federale de Lausanne (EPFL), CH-1015 Lausanne, Switzerland
//
// Reference:
// D. Sage, H. Kirshner, T. Pengo, N. Stuurman, J. Min, S. Manley, M. Unser
// Quantitative Evaluation of Software Packages for Single-Molecule Localization Microscopy
// Nature Methods 12, August 2015.
//
// Conditions of use:
// You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package smlms;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import additionaluserinterface.GridPanel;
import additionaluserinterface.Settings;
import additionaluserinterface.SpinnerDouble;
import additionaluserinterface.SpinnerInteger;
import additionaluserinterface.WalkBar;
public class CompareLocalization3DDialog extends JDialog implements WindowListener, ActionListener {
private WalkBar walk = new WalkBar("(c) Biomedical Imaging Group, EPFL 2016", false, false, false);
private String[] listUnit = new String[] { "pixel", "nm" };
private Settings settings = new Settings("CompareLocalization", "CompareLocalizationSettings.txt");
private JButton bnClose = new JButton("Close");
private JButton bnCompare = new JButton("Run (8 assessments)");
private JButton bnBrowseWobble = new JButton("Browse");
private JButton bnBrowse[] = new JButton[] { new JButton("Browse"), new JButton("Browse") };
private JButton bnLoad[] = new JButton[] { new JButton("Load"), new JButton("Load") };
private JTextField txtFile[] = new JTextField[] { new JTextField("filename.csv"), new JTextField("filename.csv") };
private JLabel lblFile[] = new JLabel[] { new JLabel("..."), new JLabel("...") };
private SpinnerDouble shiftX[] = new SpinnerDouble[] { new SpinnerDouble(0, -1000000, 100000, 1), new SpinnerDouble(0, -1000000, 100000, 1) };
private SpinnerDouble shiftY[] = new SpinnerDouble[] { new SpinnerDouble(0, -1000000, 100000, 1), new SpinnerDouble(0, -1000000, 100000, 1) };
private SpinnerDouble shiftZ[] = new SpinnerDouble[] { new SpinnerDouble(0, -1000000, 100000, 1), new SpinnerDouble(0, -1000000, 100000, 1) };
private SpinnerInteger shiftF[] = new SpinnerInteger[] { new SpinnerInteger(0, -1000000, 100000, 1), new SpinnerInteger(0, -1000000, 100000, 1) };
private JComboBox cmbUnit[] = new JComboBox[] { new JComboBox(listUnit), new JComboBox(listUnit) };
private SpinnerInteger colF[] = new SpinnerInteger[] { new SpinnerInteger(0, -1, 1000, 1), new SpinnerInteger(0, -10, 1000, 1) };
private SpinnerInteger colX[] = new SpinnerInteger[] { new SpinnerInteger(0, -1, 1000, 1), new SpinnerInteger(0, -10, 1000, 1) };
private SpinnerInteger colY[] = new SpinnerInteger[] { new SpinnerInteger(0, -1, 1000, 1), new SpinnerInteger(0, -10, 1000, 1) };
private SpinnerInteger colZ[] = new SpinnerInteger[] { new SpinnerInteger(0, -1, 1000, 1), new SpinnerInteger(0, -10, 1000, 1) };
private SpinnerInteger colI[] = new SpinnerInteger[] { new SpinnerInteger(0, -1, 1000, 1), new SpinnerInteger(0, -10, 1000, 1) };
private SpinnerInteger firstRow[] = new SpinnerInteger[] { new SpinnerInteger(1, 0, 1000, 1), new SpinnerInteger(1, 0, 1000, 1) };
private SpinnerDouble spnToleranceXY = new SpinnerDouble(10, 0, 10000, 10);
private SpinnerDouble spnToleranceZ = new SpinnerDouble(10, 0, 10000, 10);
private SpinnerDouble spnPixelsize = new SpinnerDouble(100, 0, 10000, 10);
private SpinnerDouble spnZStep = new SpinnerDouble(10, 0, 10000, 10);
private SpinnerDouble spnMinPhotons2 = new SpinnerDouble(1000, 0, 100000, 10);
private SpinnerDouble spnFieldOfViewX = new SpinnerDouble(6400, 0, 100000, 10);
private SpinnerDouble spnFieldOfViewY = new SpinnerDouble(6400, 0, 100000, 10);
private SpinnerDouble spnBorderXY = new SpinnerDouble(300, 0, 10000, 10);
private JLabel lblCorrectionX0 = new JLabel("----");
private JLabel lblCorrectionY0 = new JLabel("----");
private JTextField txtWooble = new JTextField("no", 10);
private JTextField txtName[] = new JTextField[] { new JTextField("Ground-truth"), new JTextField("Untitled") };
private JTextField txtDataset = new JTextField("Dataset name");
public CompareLocalization3DDialog() {
super(new Frame(), "Compare Localization 3D (19.06.2016)");
walk.setPreferredSize(new Dimension(250, 20));
for (int i = 0; i < 2; i++) {
settings.record("txtFile" + i, txtFile[i], "/Users/dsage/Desktop/samples");
settings.record("shiftX" + i, shiftX[i], "0");
settings.record("shiftY" + i, shiftY[i], "0");
settings.record("shiftZ" + i, shiftZ[i], "0");
settings.record("shiftF" + i, shiftF[i], "0");
settings.record("locationUnit" + i, cmbUnit[i], "nm");
settings.record("colF" + i, colF[i], "1");
settings.record("colX" + i, colX[i], "2");
settings.record("colY" + i, colY[i], "3");
settings.record("colZ" + i, colZ[i], "4");
settings.record("colI" + i, colI[i], "5");
settings.record("firstRow" + i, firstRow[i], "1");
}
settings.record("txtWooble", txtWooble, "");
settings.record("spnToleranceXY", spnToleranceXY, "250");
settings.record("spnToleranceZ", spnToleranceZ, "500");
settings.record("spnPixelsize", spnPixelsize, "100");
settings.record("spnZStep", spnZStep, "10");
settings.record("spnFieldoFViewX", spnFieldOfViewX, "6400");
settings.record("spnFieldoFViewY", spnFieldOfViewY, "6400");
settings.loadRecordedItems();
GridPanel panels[] = new GridPanel[] { new GridPanel(false), new GridPanel(false) };
GridPanel cols[] = new GridPanel[] { new GridPanel("Columns", 2), new GridPanel("Columns", 2) };
GridPanel shift[] = new GridPanel[] { new GridPanel("Shift", 2), new GridPanel("Shift", 2) };
lblCorrectionX0.setBorder(BorderFactory.createEtchedBorder());
lblCorrectionY0.setBorder(BorderFactory.createEtchedBorder());
for (int i = 0; i < 2; i++) {
txtFile[i].setPreferredSize(new Dimension(350, 22));
txtFile[i].setCaretPosition(txtFile[i].getText().length());
cols[i].place(0, 0, "Header row");
cols[i].place(0, 1, firstRow[i]);
cols[i].place(1, 0, "Frame column");
cols[i].place(1, 1, colF[i]);
cols[i].place(2, 0, "X column");
cols[i].place(2, 1, colX[i]);
cols[i].place(3, 0, "Y column");
cols[i].place(3, 1, colY[i]);
cols[i].place(4, 0, "Z column");
cols[i].place(4, 1, colZ[i]);
cols[i].place(5, 0, "Intensity column");
cols[i].place(5, 1, colI[i]);
JLabel lbl1 = new JLabel("-1 if not used, col index starts at 0");
lbl1.setBorder(BorderFactory.createEtchedBorder());
cols[i].place(6, 0, 2, 1, lbl1);
shift[i].place(0, 0, "Name");
shift[i].place(0, 1, txtName[i]);
shift[i].place(1, 0, "Frame");
shift[i].place(1, 1, shiftF[i]);
shift[i].place(2, 0, "X");
shift[i].place(2, 1, shiftX[i]);
shift[i].place(3, 0, "Y");
shift[i].place(3, 1, shiftY[i]);
shift[i].place(4, 0, "Z");
shift[i].place(4, 1, shiftZ[i]);
shift[i].place(5, 0, "Unit");
shift[i].place(5, 1, cmbUnit[i]);
JLabel lbl2 = new JLabel("Origin at the upper-left corner");
lbl2.setBorder(BorderFactory.createEtchedBorder());
shift[i].place(6, 0, 2, 1, lbl2);
lblFile[i].setBorder(BorderFactory.createEtchedBorder());
panels[i].place(1, 0, 4, 1, txtFile[i]);
panels[i].place(2, 0, 2, 1, lblFile[i]);
panels[i].place(2, 2, bnBrowse[i]);
panels[i].place(2, 3, bnLoad[i]);
panels[i].place(4, 0, 2, 1, cols[i]);
panels[i].place(4, 2, 2, 1, shift[i]);
bnLoad[i].addActionListener(this);
bnBrowse[i].addActionListener(this);
}
JLabel lblPhotons1 = new JLabel("0 (all points)");
lblPhotons1.setBorder(BorderFactory.createEtchedBorder());
GridPanel pnRun = new GridPanel("Settings");
pnRun.place(0, 0, new JLabel("Pixelsize"));
pnRun.place(0, 1, spnPixelsize);
pnRun.place(0, 2, new JLabel("nm"));
pnRun.place(1, 0, new JLabel("Tolerance XY"));
pnRun.place(1, 1, spnToleranceXY);
pnRun.place(1, 2, new JLabel("nm"));
pnRun.place(2, 0, new JLabel("Min. Photons 1"));
pnRun.place(2, 1, lblPhotons1);
pnRun.place(2, 2, new JLabel("(ref)"));
pnRun.place(3, 0, new JLabel("Min. Photons 2"));
pnRun.place(3, 1, spnMinPhotons2);
pnRun.place(3, 2, new JLabel("(ref)"));
pnRun.place(4, 0, new JLabel("FoV in X"));
pnRun.place(4, 1, spnFieldOfViewX);
pnRun.place(4, 2, new JLabel("nm"));
pnRun.place(5, 0, new JLabel("FoV in Y"));
pnRun.place(5, 1, spnFieldOfViewY);
pnRun.place(5, 2, new JLabel("nm"));
pnRun.place(6, 0, new JLabel("Excluded Border"));
pnRun.place(6, 1, spnBorderXY);
pnRun.place(6, 2, new JLabel("nm"));
GridPanel pn3D = new GridPanel("3D");
pn3D.place(0, 0, new JLabel("Z-step"));
pn3D.place(0, 1, spnZStep);
pn3D.place(1, 0, new JLabel("Tolerance Z"));
pn3D.place(1, 1, spnToleranceZ);
GridPanel pnW = new GridPanel("Wobble Correction");
pnW.place(2, 0, 1, 1, "Wobble file");
pnW.place(2, 1, bnBrowseWobble);
pnW.place(3, 0, 2, 1, txtWooble);
JLabel lbl3 = new JLabel("Depth-Dependent Lateral Distorsion ");
lbl3.setBorder(BorderFactory.createEtchedBorder());
JLabel lbl4 = new JLabel("Correction is applied only on the reference");
lbl4.setBorder(BorderFactory.createEtchedBorder());
pnW.place(4, 0, 2, 1, lbl3);
pnW.place(5, 0, 2, 1, lbl4);
GridPanel pnButton = new GridPanel(false, 1);
pnButton.place(5, 1, txtDataset);
pnButton.place(5, 2, bnClose);
pnButton.place(5, 4, bnCompare);
JTabbedPane tab = new JTabbedPane();
tab.add("Reference", panels[0]);
tab.add("Test", panels[1]);
GridPanel pnMain = new GridPanel(false, 3);
pnMain.place(2, 0, 2, 1, tab);
pnMain.place(3, 0, 1, 2, pnRun);
pnMain.place(3, 1, 1, 1, pn3D);
pnMain.place(4, 1, 1, 1, pnW);
pnMain.place(5, 0, 2, 1, pnButton);
pnMain.place(6, 0, 2, 1, walk);
addWindowListener(this);
bnClose.addActionListener(this);
bnCompare.addActionListener(this);
bnBrowseWobble.addActionListener(this);
add(pnMain);
pack();
setResizable(false);
setVisible(true);
// Center
Dimension screen = getScreenSize();
Dimension window = getSize();
if (window.width == 0)
return;
int left = screen.width / 2 - window.width / 2;
int top = (screen.height - window.height) / 4;
if (top < 0)
top = 0;
setLocation(left, top);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bnClose) {
bnLoad[0].removeActionListener(this);
bnBrowse[0].removeActionListener(this);
bnLoad[1].removeActionListener(this);
bnBrowse[1].removeActionListener(this);
bnClose.removeActionListener(this);
bnCompare.removeActionListener(this);
bnBrowseWobble.removeActionListener(this);
settings.storeRecordedItems();
dispose();
System.exit(0);
}
else if (e.getSource() == bnBrowseWobble)
browseWooble();
else if (e.getSource() == bnLoad[0])
load(0, spnBorderXY.get(), spnFieldOfViewX.get()-spnBorderXY.get(), spnBorderXY.get(), spnFieldOfViewY.get()-spnBorderXY.get());
else if (e.getSource() == bnBrowse[0])
browseFile(0);
else if (e.getSource() == bnLoad[1])
load(1, spnBorderXY.get(), spnFieldOfViewX.get()-spnBorderXY.get(), spnBorderXY.get(), spnFieldOfViewY.get()-spnBorderXY.get());
else if (e.getSource() == bnBrowse[1])
browseFile(1);
else if (e.getSource() == bnCompare)
compare();
}
public void compare() {
ArrayList<String[]> results = new ArrayList<String[]>();
results.add(CompareLocalization3D.getHeaders());
File fileRef = new File(txtFile[0].getText());
File fileTst = new File(txtFile[1].getText());
Description desca = getDescription(0);
Description descb = getDescription(1);
double minPhotons1 = 0;
double minPhotons2 = spnMinPhotons2.get();
Wobble wobble = new Wobble(txtWooble.getText());
lblCorrectionX0.setText(""+wobble.getCorrectionAt0()[0]);
lblCorrectionY0.setText(""+wobble.getCorrectionAt0()[1]);
if (fileRef.exists() && fileTst.exists()) {
walk.reset();
String dataset = txtDataset.getText();
double border = spnBorderXY.get();
double txy = spnToleranceXY.get();
double tz = spnToleranceZ.get();
Fluorophores[] ar = load(0, border, spnFieldOfViewX.get()-border, border, spnFieldOfViewY.get()-border);
Fluorophores[] a = Fluorophores.crop(ar, border, spnFieldOfViewX.get()-border, border, spnFieldOfViewY.get()-border);
Fluorophores[] b = load(1, border, spnFieldOfViewX.get()-border, border, spnFieldOfViewY.get()-border);
int algo = CompareLocalization3D.ALGO_GLOBAL_SORT_NEAREST_NEIGHBORHOOR;
CompareLocalization3D comparator = new CompareLocalization3D(desca.name, a);
results.add(comparator.run(walk, descb.name, b, 1, dataset, algo, true , null, minPhotons1, txy, tz));
results.add(comparator.run(walk, descb.name, b, 2, dataset, algo, false, null, minPhotons1, txy, tz));
results.add(comparator.run(walk, descb.name, b, 3, dataset, algo, true , wobble, minPhotons1, txy, tz));
results.add(comparator.run(walk, descb.name, b, 4, dataset, algo, false, wobble, minPhotons1, txy, tz));
results.add(comparator.run(walk, descb.name, b, 5, dataset, algo, true , null, minPhotons2, txy, tz));
results.add(comparator.run(walk, descb.name, b, 6, dataset, algo, false, null, minPhotons2, txy, tz));
results.add(comparator.run(walk, descb.name, b, 7, dataset, algo, true , wobble, minPhotons2, txy, tz));
results.add(comparator.run(walk, descb.name, b, 8, dataset, algo, false, wobble, minPhotons2, txy, tz));
CompareTable table = new CompareTable(results, CompareLocalization3D.getHeaders(), false);
table.show(1200, 200, "Compare " + desca.name + " vs. " + descb.name);
walk.finish("" + desca.name + " vs " + descb.name);
}
}
private Description getDescription(int i) {
Description desc = new Description();
desc.name = txtName[i].getText();
desc.pixelsize = cmbUnit[i].getSelectedItem().equals("nm") ? 1 : spnPixelsize.get();
desc.zstep = cmbUnit[i].getSelectedItem().equals("nm") ? 1 : spnZStep.get();
desc.shiftX = shiftX[i].get();
desc.shiftY = shiftY[i].get();
desc.shiftZ = shiftZ[i].get();
desc.shiftFrame = shiftF[i].get();
desc.colX = colX[i].get();
desc.colY = colY[i].get();
desc.colZ = colZ[i].get();
desc.colFrame = colF[i].get();
desc.colIntensity = this.colI[i].get();
desc.firstRow = this.firstRow[i].get();
return desc;
}
private Fluorophores[] load(int i, double x1, double x2, double y1, double y2) {
Description desc = getDescription(i);
LocalizationFile loc = new LocalizationFile();
Fluorophores[] fluorophoresRead = loc.read(desc, txtFile[i].getText());
Fluorophores[] fluorophores = Fluorophores.crop(fluorophoresRead, x1, x2, y1, y2);
int errors = loc.getNbErrors();
double xmax = -Double.MAX_VALUE;
double ymax = -Double.MAX_VALUE;
double zmax = -Double.MAX_VALUE;
int fmax = -Integer.MAX_VALUE;
double imax = -Double.MAX_VALUE;
double xmin = Double.MAX_VALUE;
double ymin = Double.MAX_VALUE;
double zmin = Double.MAX_VALUE;
int fmin = Integer.MAX_VALUE;
double imin = Double.MAX_VALUE;
int count = 0;
for (int f = 0; f < fluorophores.length; f++) {
for (Fluorophore fluo : fluorophores[f]) {
xmax = Math.max(xmax, fluo.xnano);
ymax = Math.max(ymax, fluo.ynano);
zmax = Math.max(zmax, fluo.znano);
fmax = Math.max(fmax, fluo.frame);
imax = Math.max(imax, fluo.photons);
xmin = Math.min(xmin, fluo.xnano);
ymin = Math.min(ymin, fluo.ynano);
zmin = Math.min(zmin, fluo.znano);
fmin = Math.min(fmin, fluo.frame);
imin = Math.min(imin, fluo.photons);
count++;
}
}
ArrayList<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "X", "" + xmin, "" + xmax });
data.add(new String[] { "Y", "" + ymin, "" + ymax });
data.add(new String[] { "Z", "" + zmin, "" + zmax });
data.add(new String[] { "Frame", "" + fmin, "" + fmax });
data.add(new String[] { "Intensity", "" + imin, "" + imax });
CompareTable table = new CompareTable(data, new String[] { "Feature", "Minimum", "Maximum" }, true);
table.show(200, 200, desc.name);
lblFile[i].setText("Fluos: " + count + " Errors:" + errors);
return fluorophores;
}
private void browseFile(int index) {
JFileChooser chooser = new JFileChooser(txtFile[index].getText());
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogTitle("Open a localization file CSV, TAB, ...");
int ret = chooser.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
String name = chooser.getSelectedFile().getAbsolutePath();
txtFile[index].setText(name);
txtFile[index].setCaretPosition(name.length());
}
}
private void browseWooble() {
JFileChooser chooser = new JFileChooser(txtWooble.getText());
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogTitle("Open a Wooble correction file *.csv");
int ret = chooser.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
String name = chooser.getSelectedFile().getAbsolutePath();
txtWooble.setText(name);
txtWooble.setCaretPosition(name.length());
}
}
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
private Dimension getScreenSize() {
if (GraphicsEnvironment.isHeadless())
return new Dimension(0, 0);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
GraphicsConfiguration[] gc = gd[0].getConfigurations();
Rectangle bounds = gc[0].getBounds();
if (bounds.x == 0 && bounds.y == 0)
return new Dimension(bounds.width, bounds.height);
else
return Toolkit.getDefaultToolkit().getScreenSize();
}
}
| Java |
2D | SMLM-Challenge/Challenge2016 | Assessment/CompareLocalization3D/src/smlms/FluorophorePair.java | .java | 1,651 | 50 | //=========================================================================================
//
// Single-Molecule Localization Microscopy Challenge 2016
// http://bigwww.epfl.ch/smlm/
//
// Author:
// Daniel Sage, http://bigwww.epfl.ch/sage/
// Biomedical Imaging Group (BIG)
// Ecole Polytechnique Federale de Lausanne (EPFL), CH-1015 Lausanne, Switzerland
//
// Reference:
// D. Sage, H. Kirshner, T. Pengo, N. Stuurman, J. Min, S. Manley, M. Unser
// Quantitative Evaluation of Software Packages for Single-Molecule Localization Microscopy
// Nature Methods 12, August 2015.
//
// Conditions of use:
// You'll be free to use this software for research purposes, but you
// should not redistribute it without our consent. In addition, we expect you to include a
// citation or acknowledgment whenever you present or publish results that are based on it.
//
//=========================================================================================
package smlms;
public class FluorophorePair implements Comparable<FluorophorePair> {
public Fluorophore ref;
public Fluorophore test;
public double cost = 0;
public FluorophorePair(Fluorophore ref, Fluorophore test, double cost) {
this.ref = ref;
this.test = test;
this.cost = cost;
}
public int compareTo(FluorophorePair pair) {
if (cost > pair.cost)
return 1;
if (cost < pair.cost)
return -1;
return 0;
}
public String toString() {
String a = ref.xnano + ", " + ref.ynano;
String b = test.xnano + ", " + test.ynano;
return a + " // " + b;
}
}
| Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.