numRows = 600;
[x, y] = meshgrid(1:numRows, 1:numRows);
w = 200;
z = exp(-(x(:) .^ 2 + y(:) .^ 2) / w^2);
zImage = reshape(z, numRows, numRows);
imshow(zImage, []);
sortedZ = sort(z, 'descend');
threshold = 1 - exp(-2)
index = round(numel(z) * threshold)
zThreshold = sortedZ(index)
mask = zImage >= zThreshold;
boundaries = bwboundaries(mask);
b = boundaries{1};
xb = b(:, 2);
yb = b(:, 1);
hold on;
plot(xb, yb, 'r-', 'LineWidth', 4);
caption = sprintf('Pixels contained in red outline = %.3f%% of the image', 100*threshold);
title(caption, 'FontSize', 20);