function runInteractiveODImageViewer(od_imgs, scan_parameter_values, file_list, options) %% Interactive OD Image Viewer % od_imgs : cell array of 2D OD images % scan_parameter_values : array of corresponding scan parameter values % file_list : cell array of corresponding filenames % options : struct with fields % .pixel_size, .magnification, .center, .font, .zoom_size, .scan_parameter % Figure hFig = figure('Name', 'OD Image Viewer', 'NumberTitle', 'off', 'Position', [50 50 1000 800]); % Get image size [Ny, Nx] = size(od_imgs{1}); % Pixel size and axes in μm dx = options.pixel_size / options.magnification; dy = dx; % square pixels x = ((1:Nx) - (Nx+1)/2) * dx * 1e6; y = ((1:Ny) - (Ny+1)/2) * dy * 1e6; % Display first image hAx = axes('Parent', hFig); hImg = imagesc(hAx, x, y, od_imgs{1}); axis(hAx, 'equal', 'tight') colormap(hAx, Colormaps.inferno()); set(hAx, 'FontSize', 14, 'YDir', 'normal'); xlabel(hAx, 'x (\mum)', 'Interpreter', 'tex', 'FontSize', 14, 'FontName', options.font); ylabel(hAx, 'y (\mum)', 'Interpreter', 'tex', 'FontSize', 14, 'FontName', options.font); title(hAx, ['Measurement: ', options.titleString], 'FontSize', 16, ... 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontName', options.font); colorbarHandle = colorbar(hAx); ylabel(colorbarHandle, 'Optical Density', 'Rotation', -90, 'FontSize', 14, 'FontName', options.font); hold(hAx, 'on') % Draw diagonal overlays once Helper.drawODOverlays(x(1), y(1), x(end), y(end)); Helper.drawODOverlays(x(end), y(1), x(1), y(end)); hold(hAx, 'off') txtHandle = text(hAx, 0.975, 0.975, '', ... 'Color', 'white', 'FontWeight', 'bold', ... 'FontSize', 24, 'Interpreter', 'tex', ... 'Units', 'normalized', ... 'HorizontalAlignment', 'right', ... 'VerticalAlignment', 'top'); % Slider sliderHandle = uicontrol('Style', 'slider', ... 'Min', 1, 'Max', length(od_imgs), 'Value', 1, ... 'SliderStep', [1/(length(od_imgs)-1), 10/(length(od_imgs)-1)], ... 'Position', [150 5 700 20], ... 'Callback', @(src, ~) updateImage(round(src.Value))); % Initialize currentIdx = 1; updateImage(currentIdx); % Arrow key callback set(hFig, 'KeyPressFcn', @(src, event) keyPressCallback(event)); %% --- Nested Functions --- function updateImage(idx) currentIdx = idx; hImg.CData = od_imgs{idx}; % Extract only filename (without path) [~, fname, ext] = fileparts(file_list{idx}); shortName = [fname, ext]; % Update figure title with shot + filename if strcmp(options.scan_parameter, 'rot_mag_fin_pol_angle') hFig.Name = sprintf('Shot %d | %s', idx, shortName); txtHandle.String = sprintf('%.1f^\\circ', scan_parameter_values(idx)); else hFig.Name = sprintf('Shot %d | %s', idx, shortName); txtHandle.String = sprintf('%.2f G', scan_parameter_values(idx)); end sliderHandle.Value = idx; drawnow; end function keyPressCallback(event) switch event.Key case 'rightarrow' if currentIdx < length(od_imgs) updateImage(currentIdx + 1); end case 'leftarrow' if currentIdx > 1 updateImage(currentIdx - 1); end end end end