Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-Chauvin committed Nov 30, 2019
0 parents commit a6514ec
Show file tree
Hide file tree
Showing 28 changed files with 141 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions CiVol.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function [Volumes, N] = CiVol(mask, D)% CIVOL Intrinsic volumes of the search region in pixel.% CiVol(mask, D) returns the intrinsic Volumes (N=Volumes(D))% If mask is a scalar, it specifies the number of pixels in the search region% E.g., [Volumes, N] = CiVol(pi*128^2, 2);% If mask is a binary matrix, where the 1's define the search region% E.g.,% mask = double(imread('faceMask.tif'));% mask = (mask - min(mask(:))) / (max(mask(:)) - min(mask(:)));% [Volumes, N] = CiVol(mask, length(size(mask)));% D (D<=3) is the dimensionality of the search region% % From K. J. Worsley's ([email protected]) stat_threshold help section:% Volumes is a vector of D+1 components, the intrinsic volumes of the search % region = [Euler characteristic, 2*caliper diameter, 1/2 surface area, volume],% e.g. [1, 4*r, 2*pi*r^2, 4/3*pi*r^3] for a sphere of radius r in 3D. For a 2D % search region, it is [1, 1/2 perimeter length, area]. The random field theory % threshold is based on the assumption that the search region is a sphere, which % is a very tight lower bound for any non-spherical region.% % See also DEMOSTAT4CI% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & FrŽdŽric Gosselin ([email protected]), 20/08/2004if length(mask) == 1, N = mask;else % the mask have to be 1 in the region of interest and 0 elsewhere minMask = min(mask(:)); maxMask = max(mask(:)); N = sum( (mask(:) - minMask)./ (maxMask - minMask) ); end;EC = 1;switch Dcase 1 Volumes(1) = EC; % Euler characteristic Volumes(2) = N; % length case 2 % N = pi*r^2 r = sqrt(N/pi); Volumes(1) = EC; % Euler characteristic Volumes(2) = pi * sqrt(N/pi) % caliper diameter Volumes(2) = pi * r % caliper diameter Volumes(3) = N; % surface area case 3 % N = (4/3)*pi*r^3 r = (3/4/pi*N)^(1/3); % r is the radius of the sphere Volumes(1) = EC; % Euler characteristic Volumes(2) = 4 * r; % 2 * caliper diameter Volumes(3) = 2 * pi * r; % 1/2 surface area Volumes(4) = N; % volumeotherwise error('Not implemented for D > 3.')end;
Expand Down
1 change: 1 addition & 0 deletions DemoStat4Ci.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% DEMOSTAT4CI illustrates the usage of the Stat2Ci toolbox on two classification images from:% Gosselin, F. & Schyns, P. G. (2001). Bubbles: A technique to reveal the use of information % in recognition. Vision Research, 41, 2261-2271.% The Stat4Ci toolbox allows to perform the Pixel and the Cluster tests, both based on Random Field % Theory. These tests are easy to apply, requiring a mere four pieces of information; and they % typically produce statistical thresholds (or p-values) lower than the standard Bonferroni correction.% % An excellent non-technical reference is:% K. J. Worsley (1996) the geometry of random image. Chance, 9, 27-40.% % We borrowed from several sources: the STAT_THRESHOLD function was written by Keith Worsley for the fmristat toolbox% (http://www.math.mcgill.ca/~keith/fmristat); and our DISPLAYCI function calls many functions from the % Image Processing toolbox.% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & FrŽdŽric Gosselin ([email protected]), 20/08/2004% % Loads a classification imageSCi = double(imread('GenderFG.tiff')); % from Gosselin & Schyns, 2001, Experiment 1, GENDER, subject FG SCi = double(imread('exnexFG.tiff')); % from Gosselin & Schyns, 2001, Experiment 1, GENDER, subject FG SCi = cIm2hrCi(SCi);sigma_b = 20; %std of smoothing filter% % Specifies a search space; here: the face areaS_r = double(imread('faceMask.tiff'));S_r = (S_r - min(S_r(:))) / (max(S_r(:))-min(S_r(:)));% % Extracts the area outside the mask; used for the estimation of expected mean and variance of the CivecSCi = SCi(eq(S_r,0));% % Z-transforms the SCiRes = ZTransSCi(SCi,mean(vecSCi(:)),std(vecSCi(:)));Res.ZSCi = Res.ZSCi.*S_r;% % Performs the Pixel or Cluster testp = .05; %p-valuetC = 2.7; %threshold (for Cluster test)Res = StatThresh(Res,p,sigma_b,tC,S_r);% % Displays the resultsbackground = double(imread('w1H.JPG')); % a face used by Gosselin & Schyns, 2001, Experiment 1tCi = DiplayRes(Res,background); % the results of one of the tests with a background
Expand Down
1 change: 1 addition & 0 deletions DiplayRes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function Res = DiplayRes(Res,background); % DISPLAYCI displays the results of the Pixel and Cluster tests.% tCi = DisplayCi(Res,[background]) returns, for the Pixel test % (typeTest = 'P'), the Z-scores (tCi) above threshold (tP); and, for the Cluster test % (typeTest = 'C'), the Z-scores (tCi) above threshold (tC) and belonging to clusters % greater than the minimum size (k).% % Res.ZCi = Z-transformed smooth classification image (see ZTRANSCI) % Res.tC = Cluster test threshold (set by the user)% Res.k = Minimun cluster size (see STAT_THRESHOLD)% Res.tP = Pixel test threshold (see STAT_THRESHOLD)% Res.FWHM = full width half maximum of the Gaussian smoothing filter (see HALFMAX)% Res.p = p-value for Pixel and Cluster tests (set by user)% [background] = image overlaid to the classification image to help interpretation.% With red pixels indicating the regions that attained statistical significance. % % E.g.,% SCi = double(imread('GenderCi.tiff')); % sCi = cIm2hrCi(SCi); % sigma_b = 20; % S_r = double(imread('faceMask.tif'));% vecSCi = SCi(eq(S_r,0));% ZSCi = ZTransSCi(SCi,[mean(vecSCi(:)),std(vecSCi(:))]);% ZSCi = ZSCi.*S_r;% P = .05; % tC = 2.7; % Res = StatThresh(ZSCi,p,sigma_b,tC,S_r);% background = double(imread('w1H.JPG')); % tCi = DiplayRes(Res,background); % % For both tests, DISPLAYCI also returns a table with all relevant statistics (tC, tP, % p, sizes of significant clusters, and so on).%% Requires the ImageProcessing Toolbox.% % See also STATRESH, ZTRANSCI, DEMOSTAT4CI% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2005). Accurate % statistical tests for smooth classification images.% % Alan Chauvin & FrŽdŽric Gosselin ([email protected]), 01//03/2005% ------------------------------------------------------------% 1. displays cluster result cCi = ( Res.ZSCi >= Res.tC);[LabelClC ,nbClusterC] = BWLABEL(cCi); % labels all clusters in Res.ZSCiif nbClusterC ~=0 for ii = 1 : nbClusterC cm(ii) = length(find(LabelClC == ii)); end; %dbstop at 65 cm = [[1:nbClusterC];cm]; if nbClusterC > 1 %cm = sortrows(cm,2); % sorts clusters per size cm = sortrows(cm',1)'; % sorts clusters per size end; ii = 0;c= 0; while ii < nbClusterC ii = ii + 1; if cm(2,ii) < Res.k LabelClC(find(LabelClC == cm(1,ii))) = 0; else c = c +1; maxZ(c) = max(max(Res.ZSCi(find(LabelClC == cm(1,ii))))); sizeZ(c) = cm(2,ii); [I,J]=find(LabelClC == cm(1,ii)); yZ(c) = round((max(I)+min(I))/2); xZ(c) = round((max(J)+min(J))/2); LabelClC(find(LabelClC == cm(1,ii))) = 1; end; end; for i = 1 : c Results(i,2) = Res.tC; Results(i,3) = sizeZ(i); Results(i,4) = sizeZ(i)/Res.FWHM/Res.FWHM'; Results(i,5) = maxZ(i); Results(i,6) = xZ(i); Results(i,7) = yZ(i); if i == c Results(i,1) = 67; % ascii code for 'C' else Results(i,1) = 32; % ascii code for 'space' end; end; if c, clear maxZ sizeZ yZ xZ;end; if c > 0 Results = flipud(sortrows(Results,3)); fprintf('\n'); fprintf('\tt\t\tsize\tresels\tZmax\tx\ty\n'); fprintf('\t-----------------------------------------\n'); fprintf('%c\t[%.2f]\t%d\t\t%.2f\t%.2f\t%d\t%d\n',Results'); else fprintf('\t-----------------------------------------\n'); fprintf('\tno cluster reach significance\n') end;else fprintf('\t-----------------------------------------\n'); fprintf('\tno cluster reach significance\n')end;% --------------------------------------------------------% 2. displays pixel resultspCi = ( Res.ZSCi >= Res.tP);nbClusterP = ( sum(pCi(:)) >= 1 );if nbClusterP fprintf('\t-----------------------------------------\n'); fprintf('P\t%.2f\t-\t-\t-\t-\t-\n',Res.tP);end;fprintf('\n');fprintf('p-value = [%.2f]\n',Res.p);fprintf('FWHM == [%.1f]\n',Res.FWHM);fprintf('Minimum cluster size = %.1f\n',max(Res.k,0));% --------------------------------------------------------% 3. displays the figureif nbClusterC == 0 & nbClusterP == 0; Res.tCi = zeros(Res>ZSci); return;end;figurefor ii = 1 : 2 if ii == 1 % 3.1 Pixel test t = Res.tP; LabelCl = ones(size(Res.ZSCi)); Res.PixTest = (Res.ZSCi >= t) .* LabelCl; tCi = Res.PixTest; ss = sprintf('Pixel Test'); else % 3.1 Cluster test t = Res.tC; LabelCl = LabelClC; Res.ClusTest = (Res.ZSCi >= t) .* LabelCl; tCi = Res.ClusTest; ss = sprintf('Cluster Test'); end; subplot(1,2,ii) if ~exist('background') image(tCi);axis image;axis off s = sprintf('t = %.2f, pval = %.3f',t,p); title(s) else % thresholded classification image is overlaid on an image background = 2*( ( background-min(background(:)) ) / ( max(background(:))-min(background(:)) ) ) - 1; for ii = 1 : 3 colorIma(:,:,ii) = 2*background; end; mmax = max(Res.ZSCi(:)); mmin = min(Res.ZSCi(:)); cIma = colorIma/2; cIma(:,:,1) = colorIma(:,:,1)/2 + tCi; cIma = ( cIma-min(cIma(:)) ) / ( max(cIma(:))-min(cIma(:))+0.0001 ); tCi = cIma; % figure,imshow(cIma);axis on imagesc(cIma); axis square;colormap(jet);axis off s = sprintf('%s, t = %.2f, pval = %.3f',ss, t,Res.p); title(s) if ii == 1 % 3.1 Pixel test Res.PixTest = cIma; else % 3.1 Cluster test Res.ClusTest = cIma; end; end;end;clear cm
Expand Down
Binary file added ExnexFG.tiff
Binary file not shown.
Binary file added GenderFG.tiff
Binary file not shown.
Binary file added Gosselin & Schyns (2001)/.DS_Store
Binary file not shown.
Binary file added Gosselin & Schyns (2001)/ExnexFG.tiff
Binary file not shown.
Binary file added Gosselin & Schyns (2001)/GenderFG.tiff
Binary file not shown.
Binary file added Gosselin & Schyns (2001)/facemask.tiff
Binary file not shown.
Binary file added Gosselin & Schyns (2001)/w1H.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions HalfMax.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function FWHM = HalfMax(sigma);% HALFMAX Full width half maximum of a Gaussian filter.% HalfMax returns FWHM, the full width half maximum of% a Gaussian filter of standard deviation equals to sigma pixels.% E.g., FWHM = HalfMax(20);% % See also DEMOSTAT4CI% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & FrŽdŽric Gosselin ([email protected]), 20/08/2004FWHM = sigma * sqrt(8*log(2));
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Stat4Ci-Toolbox

1 change: 1 addition & 0 deletions SmoothCi.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function [Sci, h] = SmoothCiConv(ci,sigma)% SMOOTHCI Smoothes a 2D image.% SmoothCi(ci,sigma) convolves a 2D image (ci) with a 2D Gaussian % filter of standard deviation equals to sigma pixels.% E.g.,% ci = double(imread('GenderFG.tiff'));% Sci = SmoothCi(ci,20);% or [Sci, h] = SmoothCi(ci,20); if the smoothing filter is needed% % Requires the ImageProcessing Toolbox.% % See also DEMOSTAT4CI% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & FrŽdŽric Gosselin ([email protected]), 20/08/2004TNoyau = 6*sigma;h = fspecial('gaussian',ceil(TNoyau),sigma);Sci = filter2(h,ci);
Expand Down
1 change: 1 addition & 0 deletions StatThresh.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function Res = StatThresh(Res,p,sigma_b,tC,S_r);FWHM = HalfMax(sigma_b); % computes the full width half maximumif exist('S_r') D = length(size(S_r)); % number of dimensions in the search space [volumes, N] = CiVol(sum(S_r(:)), D) % computes the intrinsic volumeselse D = length(size(ZSCi)); % number of dimensions in the search space [volumes, N] = CiVol(sum(ZSCi(:)), D) % computes the intrinsic volumesend; [tP, k] = stat_threshold(volumes, N, FWHM, Inf, p, tC); % the actual statistical testsRes.tP = tP;Res.p = p;Res.tC = tC;Res.k = k;Res.FWHM = FWHM;
Expand Down
1 change: 1 addition & 0 deletions ZTransSCi.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function Res = ZtransSCi(SCi,varargin)% ZTRANSCI Z-transforms a smooth classification image.% In ZtransCi(SCi, meanSCi, stdSCi) the mean (meanSCi) and the standard % deviation (stdSCi) of the classification image are provided by the user.% E.g.,% mask = double(imread('faceMask.tif'));% mask = (mask - min(mask(:))) / (max(mask(:)) - min(mask(:)));% Ci = double(imread('GenderFG.tiff'));% vecCi = Ci(eq(mask, 0));% ZCi = ZTransCi(Ci, mean(vecCi(:)), std(vecCi(:)));% % In ZtransCi(SCi, meanSCi) the mean (meanSCi) of the classification image % is provided by the user and the standard deviation is estimated from the data.% % In ZtransCi(SCi) the mean and the standard deviation of the classification image % are estimated from the data.% % In ZtransCi(Ci1, n1, Ci2, n2, sigmaNoise, smoothFilter),% Ci1 = sum of white noise fields that led to a type 1 response (e.g., correct) % n1 = number of type 1 response% Ci2 = sum of white noise fields that led to a type 2 response (e.g., incorrect) % n2 = number of type 2 response % sigmaNoise = standard deviation of white noise% smoothFilter = Gaussian filter used to smooth the classification image% For an explanation, see:% Chauvin, Worsley, Schyns, Arguin & Gosselin (2004). A sensitive statistical % test for smooth classification images.% % See also SMOOTHCI, DEMOSTAT4CI% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & FrŽdŽric Gosselin ([email protected]), 20/08/2004% the mean and the std are estimated if not providedswitch nargincase 6, cCi = SCi; nc = varargin{1}; iCi = varargin{2}; ni = varargin{3}; sigmaNoise = varargin{4}; smoothFilter = varargin{5}; n = ni + nc; % number of trial rhoC = (cCi/nc-iCi/ni)*nc*ni/n; NvarX = n*sigmaNoise^2*sum(smoothFilter(:).^2); NvarY = nc*ni/n; % Z transform Res.ZSCi = sqrt(n)*rhoC/sqrt(NvarX)/sqrt(NvarY);case 5, Ci = SCi; nc = varargin{1}; ni = varargin{2}; sigmaNoise = varargin{3}; smoothFilter = varargin{4}; n = ni + nc; % number of trial rhoC = Ci; NvarX = n*sigmaNoise^2*sum(smoothFilter(:).^2); NvarY = nc*ni/n; % Z transform Res.ZSCi = sqrt(n)*rhoC/sqrt(NvarX)/sqrt(NvarY); case 3 muCi = varargin{1}; stdCi = varargin{2}; % Z transform Res.ZSCi = (SCi - muCi) / stdCi; case 2 stdCi = std(SCi(:)); muCi = varargin{1}; % Z transform Res.ZSCi = (SCi - muCi) / stdCi; case nargin == 1 muCi = mean(SCi(:)); stdCi = std(SCi(:)); % Z transform Res.ZSCi = (SCi - muCi) / stdCi;otherwise error('Incorrect number of arguments.')end
Expand Down
1 change: 1 addition & 0 deletions cIm2hrCi.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function hrCi = cIm2hrCi(cIm)% CIM2HRCI Transforms a uint8 color image (cIm) into a 2D high-res % (24 bits) classification image (hrCi).% E.g., im = rand(256,256,3);% cIm = uint8((256 - 1) * im);% hrCi = cIm2hrCi(cIm);%% See also DEMOSTAT4CI, HRCI2CIM%% The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & Fr�d�ric Gosselin ([email protected]), 20/08/2004 cIm = double(cIm);hrCi = cIm(:,:,1) * 256^2 + cIm(:,:,2) * 256 + cIm(:,:,3);
Expand Down
Binary file added exnexfg.tiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added facemask.tiff
Binary file not shown.
Binary file added facemask.tiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added genderfg.tiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions hrCi2cIm.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function cIm = hrCi2cIm(hrCi)% HRCI2CIM Transforms a 2D high-res (24 bits) classification image (hrCi)% into a uint8 color image (cIm). The color image can then be saved in % your favorite image format without loss of information (e.g., TIF). % E.g., Ci = rand(256,256);% hrCi = round((256^3 - 1) * Ci);% cIm = hrCi2cIm(hrCi);% % See also DEMOSTAT4CI, CIM2HRCI% % The Stat4Ci toolbox is free (http://mapageweb.umontreal.ca/gosselif/stat4ci.html); if you use % it in your research, please, cite us:% Chauvin, A., Worsley, K. J., Schyns, P. G., Arguin, M. & Gosselin, F. (2004). A sensitive % statistical test for smooth classification images.% % Alan Chauvin & Fr�d�ric Gosselin ([email protected]), 20/08/2004tIm(:,:,3) = mod(hrCi, 256);tIm(:,:,2) = mod(hrCi - squeeze(tIm(:,:,3)), 256^2);tIm(:,:,1) = mod(hrCi - squeeze(tIm(:,:,3)) - squeeze(tIm(:,:,2)), 256^3);tIm(:,:,2) = tIm(:,:,2) / 256;tIm(:,:,1) = tIm(:,:,1) / 256^2;cIm = uint8(tIm);
Expand Down
Binary file added html/.DS_Store
Binary file not shown.
Loading

0 comments on commit a6514ec

Please sign in to comment.