function tim_demo %TIM_DEMO show how a few functions that are vector-based can do a lot of work % with minimal overhead. % Preallocate memory for the three pictures we'll be imaging. Replace this with % your own (JPG) image to see how the speed scales with size. im = imread('large.jpg', 'JPG'); im2 = im; im3 = im; % from MATLAB help on 'figure' scrsz = get(0, 'ScreenSize'); [im_y im_x unused] = size(im); aspect_ratio = im_y / im_x; figure_box = [1, 1, (scrsz(4) - 100) / (aspect_ratio * 3), scrsz(4) - 100]; figure('Position', figure_box); % Display the original image subplot(3,1,1); imagesc(im); axis off; % Make radial gaussian profile. The middle element of the matrix will have % value 1, and the values of values 'farther away' from the center value die off % until they reach 1.5 standard deviations at the nearest edge point. x = (1:im_x) - ceil(im_x / 2); y = (1:im_y) - ceil(im_y / 2); r = (ones(im_y, 1) * x .^ 2 + y' .^ 2 * ones(1, im_x)) .^ 0.5; z = normpdf(r, 0, min(im_x, im_y) / 3); z = z / max(max(z)); % Scale red channel by multiplying it with our gaussian envelope. uint8() and % double() are matching the datatype between the matrix we made and the image. im2(:,:,1) = uint8(double(im2(:,:,1)) .* z); subplot(3,1,2); imagesc(im2); axis off; % Now reuse our matrix by shifting the center around for each channel. Also, % this time use a 3D array so that we can alter all three channels with one % multiplication command. sep = 100; z(:,:,2) = circshift(z, [sep sep]); z(:,:,3) = circshift(z(:,:,1), [sep, -sep]); z(:,:,1) = circshift(z(:,:,1), [-floor(sep / sqrt(3)), 0]); % Scale all channels at once with 3D matrix im3 = uint8(double(im3) .* z); subplot(3,1,3); imagesc(im3); axis off;