Contents

% Frank Sommer
% 14.12.2005
% problem 4: timestack image

clearing and constant setting

%close all things
clear;
close all;
clc;

%variables and constant
bool_exit = 0;
threshold = 0.7;                % intensity threshold for swash edge
maxima = []; stack = [];        % allocate output array
filenum = 34;                   % 34 number of images
line = 690;                     % line for cropping

get the first image

%load data with dialog
[filename, pathname] = uigetfile({'*.jpg', 'JPG-Images (*.jpg)'},...
    'load the 1st image (e.g. prefix_1.jpg)');
imagePrefix = strrep(filename, '1.jpg', '');

if (strcmp(imagePrefix,filename) == false)

    % get the information about the image
    info=imfinfo([pathname,imagePrefix,'1'],'jpg');

    % initiate waitbar

    h = waitbar(0,'Executing Script, wait........', 'Name',...
        'Problem 4: Waitbar', 'CreateCancelBtn','button_callback',...
        'CloseRequestFcn','button_callback');    % initiate 'waitbar'

    % calculate the stack image

    for i=1:filenum,
        if (bool_exit == 0)
            %construct the filename
            filename = [[pathname,imagePrefix],num2str(i),'.jpg'];
            I = imread(filename);
            hf = rgb2gray(double(I)/255);
            hf = imcrop(hf, [0 line info.Width 20]);
            ehf = histeq(hf, 32);
            xi = [0 info.Width]; yi = [10 10];  % image slice to select
            c = improfile(ehf,xi,yi);  % image intensity profile
            c = slidingavg(c,7);       % smooth with 7-point moving average

            index = find(c>=threshold);    % find all swash regions
            s_edge = index(length(index)); % most landward swash region
            maxima = [maxima; s_edge];
            stack = [stack; c'];           % timestack array (' invert c)
            waitbar(i/filenum)             % next increment to 'waitbar'
        else
            break;
        end
    end

    % plot the intensity and the stack image

    if (bool_exit == 0) %calculation is gone till end
        delete(h);            % close the waitbar

        %labelticks for axes
        time = (6:1/2:22.5);
        x = (1:1:1024);

        %-------------------- create window -------------------------------
        figure(2),
        set(2, 'Name', 'Problem 4: Timestack Image', 'Position', ...
            [200 100 600 480], 'Color', [0 0 0.3],'NumberTitle','off');
        %------------------------------------------------------------------

        ax1 = subplot (3,3,1:3);               % plot intensity profile
            h1 = plot(c);
            axis([0 1024 0 1]);
            t1 = text(-75,0.5,'Intensity');
        ax2 = subplot (3,3,4:9);               % show timestack image
            h2 = imagesc(x,time,stack);
            colormap gray;
            hold on;
            h3 = plot(maxima, time, 'ro');
            hold on;
            t3 = text(300,14,'maximum over threshold');
            title('SHORELINE HISTORY','fontweight','bold','color',...
                [0.5 0.5 0.5]);
            t2 = text(-75,16,'Time (hours on 24-JUL-2005)');
            xlabel('Cross-shore distance (pixels)');

        %----------------- formatting zone --------------------------------
        set(h1, 'Color', [0.1 0.9 0.1]);
        set([ax1 ax2], 'XColor', [1 1 1], 'Color', [0 0 0], ...
            'YColor', [1 1 1], 'fontsize',8);
        set([t1 t2], 'horizontalalignment','center','rotation',90,...
            'fontsize',8,'fontangle','italic', 'color', [1 1 1]);
        set(t3, 'color', [1,0,0], 'fontweight', 'bold');
    end
% show error dialog, if invalid image was chosen
else
    errordlg('invalid image name, e.g. prefix_1.jpg');
end