I1 = imread('cameraman.tif');

I1Norm = IrDbl/double(intmax('uint8'));

[u1,v1] = gradient(I1Norm,1,1);

[x,y] = meshgrid(1:size(I1Norm,1),1:size(I1Norm,2));

I1Sum = sum(u1(:)+v1(:));

Ibsum = nan(1,nBootStraps);

Itemp = reshape(I1Norm(randperm(numel(I1Norm))),size(I1Norm));

[uTemp,vTemp] = gradient(Itemp,1,1);

Ibsum(i) = sum(uTemp(:)+vTemp(:));

prc = abs([0,100]-(100-alpha)/2);

isSignificantlyDifferent = I1Sum < CI(1) || I1Sum > CI(2);

tiledlayout(2,2, 'Padding','compact','TileSpacing','compact')

qh1 = quiver(x,y,u1,v1,1,'LineWidth',1);

qh2 = quiver(x,y,uTemp,vTemp,1,'LineWidth',1);

title('Example of shuffled image')

histogram(Ibsum,'DisplayName','VectorSums')

xline(CI(1),'DisplayName','LowBound');

xline(CI(2),'DisplayName','HighBound')

xline(I1Sum, 'm-', 'DisplayName','TestImage')

title('Distribution of bootstrapped vector sums')

subtitle(sprintf('Significantly different = %.0f', isSignificantlyDifferent))

legend('Location','SouthOutside','Orientation','Horizontal')