% Define zoom factor (1 = no zoom, higher values = more zoom)
zoom_factor = 3; % Adjust this value to control how zoomed in the image is

% Define which panel to use (1 for first panel, 2 for second, etc.)
selected_panel = 1; % Adjust this value to select different panels

site_names = {'Site1NNN','Site3N', 'Site5N', 'Site6', 'Site7N', 'Site8', 'Site9', 'Site9a', 'Site10', 'Site12', 'Site13', 'Site16', 'Site17'};
figure;

for idx = 1:numel(site_names)
    matFilename = site_names{idx};
    data = load(matFilename);
    
    % Check if the selected panel exists for this site
    if size(data.co_sar, 3) < selected_panel
        fprintf('Skipping %s: Selected panel %d does not exist\n', matFilename, selected_panel);
        continue;
    end
    
    nexttile;
    
    % Find the center of mass of the mask
    stats = regionprops(data.mask, 'Centroid');
    center = stats.Centroid;
    
    % Calculate the size of the cropped region
    mask_size = size(data.mask);
    crop_size = min(mask_size) / zoom_factor;
    half_crop = round(crop_size / 2);
    
    % Calculate cropping boundaries
    top = max(1, round(center(2) - half_crop));
    bottom = min(mask_size(1), round(center(2) + half_crop));
    left = max(1, round(center(1) - half_crop));
    right = min(mask_size(2), round(center(1) + half_crop));
    
    % Crop the selected panel of SAR image and the mask
    cropped_sar = data.co_sar(top:bottom, left:right, selected_panel);
    cropped_mask = data.mask(top:bottom, left:right);
    
    % Create an RGB version of the cropped grayscale image
    sar_rgb = repmat(cropped_sar, [1, 1, 3]);
    
    % Find the boundaries of the cropped mask
    B = bwboundaries(cropped_mask, 'noholes');
    B = vertcat(B{:});
    k = boundary(B);

    
    imshow(sar_rgb);
    hold on;
    
    % Define fill color (RGB, no alpha) - Pastel green
    fill_color = [144, 238, 144] / 255; % Light green
    
    % Define face alpha (transparency)
    face_alpha = 0.2;
    
    % Fill the area inside the boundary with the transparent pastel green color
    fill(B(k,2), B(k,1), fill_color, 'FaceAlpha', face_alpha);
    
    % Draw the boundary line in pastel green

    plot(B(k,2), B(k,1), 'Color', fill_color, 'LineWidth', 2);
    
    
    axis equal
    title(sprintf('%s - Panel %d', matFilename, selected_panel))
end
