Latest Analysis scripts.
This commit is contained in:
parent
c5ebb76b9d
commit
50722c5140
@ -61,40 +61,6 @@ else
|
|||||||
od_imgs{i} = absimages(:, :, i);
|
od_imgs{i} = absimages(:, :, i);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
%% Display Images
|
|
||||||
|
|
||||||
figure(1)
|
|
||||||
clf
|
|
||||||
set(gcf,'Position',[50 50 950 750])
|
|
||||||
|
|
||||||
% Calculate the x and y limits for the cropped image
|
|
||||||
y_min = center(1) - span(2) / 2;
|
|
||||||
y_max = center(1) + span(2) / 2;
|
|
||||||
x_min = center(2) - span(1) / 2;
|
|
||||||
x_max = center(2) + span(1) / 2;
|
|
||||||
|
|
||||||
% Generate x and y arrays representing the original coordinates for each pixel
|
|
||||||
x_range = linspace(x_min, x_max, span(1));
|
|
||||||
y_range = linspace(y_min, y_max, span(2));
|
|
||||||
|
|
||||||
% Display the cropped image
|
|
||||||
for k = 1 : length(od_imgs)
|
|
||||||
imagesc(x_range, y_range, od_imgs{k})
|
|
||||||
axis equal tight;
|
|
||||||
hcb = colorbar;
|
|
||||||
hL = ylabel(hcb, 'Optical Density', 'FontSize', 16);
|
|
||||||
set(hL,'Rotation',-90);
|
|
||||||
colormap jet;
|
|
||||||
set(gca,'CLim',[0 3.0]);
|
|
||||||
set(gca,'YDir','normal')
|
|
||||||
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
|
||||||
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
|
||||||
xlabel('Horizontal', 'Interpreter', 'tex','FontSize',16);
|
|
||||||
ylabel('Vertical', 'Interpreter', 'tex','FontSize',16);
|
|
||||||
|
|
||||||
drawnow
|
|
||||||
pause(0.5)
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Get rotation angles
|
%% Get rotation angles
|
||||||
theta_values = zeros(1, length(files));
|
theta_values = zeros(1, length(files));
|
||||||
@ -116,7 +82,8 @@ end
|
|||||||
fft_imgs = cell(1, nimgs);
|
fft_imgs = cell(1, nimgs);
|
||||||
|
|
||||||
% Create VideoWriter object for movie
|
% Create VideoWriter object for movie
|
||||||
videoFile = VideoWriter('Single_Shot_FFT.avi', 'Motion JPEG AVI');
|
videoFile = VideoWriter('Single_Shot_FFT.mp4', 'MPEG-4');
|
||||||
|
videoFile.Quality = 100; % Set quality to maximum (0–100)
|
||||||
videoFile.FrameRate = 2; % Set the frame rate (frames per second)
|
videoFile.FrameRate = 2; % Set the frame rate (frames per second)
|
||||||
open(videoFile); % Open the video file to write
|
open(videoFile); % Open the video file to write
|
||||||
|
|
||||||
@ -127,9 +94,9 @@ for k = 1 : length(od_imgs)
|
|||||||
|
|
||||||
figure(2);
|
figure(2);
|
||||||
clf
|
clf
|
||||||
set(gcf,'Position',[50 50 1500 550])
|
set(gcf,'Position',[500 100 1000 800])
|
||||||
set(gca,'FontSize',16,'Box','On','Linewidth',2);
|
t = tiledlayout(2, 2, 'TileSpacing', 'compact', 'Padding', 'compact'); % 1x4 grid
|
||||||
t = tiledlayout(1, 3, 'TileSpacing', 'compact', 'Padding', 'compact'); % 1x2 grid
|
font = 'Bahnschrift';
|
||||||
|
|
||||||
% Calculate the x and y limits for the cropped image
|
% Calculate the x and y limits for the cropped image
|
||||||
y_min = center(1) - span(2) / 2;
|
y_min = center(1) - span(2) / 2;
|
||||||
@ -142,37 +109,48 @@ for k = 1 : length(od_imgs)
|
|||||||
y_range = linspace(y_min, y_max, span(2));
|
y_range = linspace(y_min, y_max, span(2));
|
||||||
|
|
||||||
% Display the cropped image
|
% Display the cropped image
|
||||||
nexttile
|
ax1 = nexttile;
|
||||||
imagesc(x_range, y_range, IMG)
|
imagesc(x_range, y_range, IMG)
|
||||||
% Define normalized positions (relative to axis limits)
|
% Define normalized positions (relative to axis limits)
|
||||||
x_offset = 0.025; % 5% offset from the edges
|
x_offset = 0.025; % 5% offset from the edges
|
||||||
y_offset = 0.025; % 5% offset from the edges
|
y_offset = 0.025; % 5% offset from the edges
|
||||||
% Top-right corner (normalized axis coordinates)
|
% Top-right corner (normalized axis coordinates)
|
||||||
text(1 - x_offset, 1 - y_offset, ['Angle: ', num2str(theta_values(k), '%.1f')], ...
|
hText = text(1 - x_offset, 1 - y_offset, ['Angle: ', num2str(theta_values(k), '%.1f')], ...
|
||||||
'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
||||||
|
|
||||||
axis equal tight;
|
axis equal tight;
|
||||||
hcb = colorbar;
|
hcb = colorbar;
|
||||||
hL = ylabel(hcb, 'Optical Density', 'FontSize', 16);
|
colormap(ax1, 'jet');
|
||||||
|
set(gca, 'FontSize', 14); % For tick labels only
|
||||||
|
hL = ylabel(hcb, 'Optical Density');
|
||||||
set(hL,'Rotation',-90);
|
set(hL,'Rotation',-90);
|
||||||
set(gca,'YDir','normal')
|
set(gca,'YDir','normal')
|
||||||
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
||||||
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
||||||
xlabel('X', 'Interpreter', 'tex','FontSize',16);
|
hXLabel = xlabel('X (pixels)', 'Interpreter', 'tex');
|
||||||
ylabel('Y', 'Interpreter', 'tex','FontSize',16);
|
hYLabel = ylabel('Y (pixels)', 'Interpreter', 'tex');
|
||||||
|
hTitle = title('OD Image', 'Interpreter', 'tex');
|
||||||
|
set([hXLabel, hYLabel, hL, hText], 'FontName', font)
|
||||||
|
set([hXLabel, hYLabel, hL], 'FontSize', 14)
|
||||||
|
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||||
|
|
||||||
nexttile
|
ax2 = nexttile;
|
||||||
imagesc(x_range, y_range, IMGBIN)
|
imagesc(x_range, y_range, IMGBIN)
|
||||||
axis equal tight;
|
axis equal tight;
|
||||||
hcb = colorbar;
|
hcb = colorbar;
|
||||||
|
colormap(ax2, 'parula');
|
||||||
|
set(gca, 'FontSize', 14); % For tick labels only
|
||||||
set(gca,'YDir','normal')
|
set(gca,'YDir','normal')
|
||||||
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
||||||
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
||||||
xlabel('X', 'Interpreter', 'tex','FontSize',16);
|
hXLabel = xlabel('X (pixels)', 'Interpreter', 'tex');
|
||||||
ylabel('Y', 'Interpreter', 'tex','FontSize',16);
|
hYLabel = ylabel('Y (pixels)', 'Interpreter', 'tex');
|
||||||
title('Denoised - Masked - Binarized','FontSize',16);
|
hTitle = title('Denoised - Masked - Binarized', 'Interpreter', 'tex');
|
||||||
|
|
||||||
nexttile
|
set([hXLabel, hYLabel, hL], 'FontName', font)
|
||||||
|
set([hXLabel, hYLabel, hL], 'FontSize', 14)
|
||||||
|
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||||
|
|
||||||
|
ax3 = nexttile;
|
||||||
[rows, cols] = size(IMGFFT);
|
[rows, cols] = size(IMGFFT);
|
||||||
zoom_size = 50; % Zoomed-in region around center
|
zoom_size = 50; % Zoomed-in region around center
|
||||||
mid_x = floor(cols/2);
|
mid_x = floor(cols/2);
|
||||||
@ -184,69 +162,46 @@ for k = 1 : length(od_imgs)
|
|||||||
x_offset = 0.025; % 5% offset from the edges
|
x_offset = 0.025; % 5% offset from the edges
|
||||||
y_offset = 0.025; % 5% offset from the edges
|
y_offset = 0.025; % 5% offset from the edges
|
||||||
% Top-right corner (normalized axis coordinates)
|
% Top-right corner (normalized axis coordinates)
|
||||||
text(1 - x_offset, 1 - y_offset, ['Angle: ', num2str(theta_values(k), '%.1f')], ...
|
% hText = text(1 - x_offset, 1 - y_offset, ['Angle: ', num2str(theta_values(k), '%.1f')], ...
|
||||||
'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
% 'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
||||||
axis equal tight;
|
axis equal tight;
|
||||||
hcb = colorbar;
|
hcb = colorbar;
|
||||||
|
colormap(ax3, 'jet');
|
||||||
|
set(gca, 'FontSize', 14); % For tick labels only
|
||||||
set(gca,'YDir','normal')
|
set(gca,'YDir','normal')
|
||||||
xlabel('X', 'Interpreter', 'tex','FontSize',16);
|
hXLabel = xlabel('X (pixels)', 'Interpreter', 'tex');
|
||||||
ylabel('Y', 'Interpreter', 'tex','FontSize',16);
|
hYLabel = ylabel('Y (pixels)', 'Interpreter', 'tex');
|
||||||
title('Fourier Power Spectrum','FontSize',16);
|
hTitle = title('Fourier Power Spectrum', 'Interpreter', 'tex');
|
||||||
|
set([hXLabel, hYLabel, hL, hText], 'FontName', font)
|
||||||
|
set([hXLabel, hYLabel, hL], 'FontSize', 14)
|
||||||
|
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||||
|
|
||||||
drawnow
|
% Plot the angular structure factor
|
||||||
pause(0.5)
|
%{
|
||||||
|
nexttile
|
||||||
|
[theta_vals, angular_intensity] = computeAngularDistribution(zoomedIMGFFT, 10, 20, 100, 75);
|
||||||
|
polarhistogram('BinEdges', theta_vals, 'BinCounts', angular_intensity, ...
|
||||||
|
'FaceColor', [0.2 0.6 0.9], 'EdgeColor', 'k');
|
||||||
|
set(gca, 'FontSize', 14); % For tick labels only
|
||||||
|
hTitle = title('Angular Distribution', 'Interpreter', 'tex');
|
||||||
|
set(hTitle, 'FontName', font)
|
||||||
|
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||||
|
%}
|
||||||
|
% Plot the angular structure factor
|
||||||
|
nexttile
|
||||||
|
[theta_vals, S_theta] = computeAngularStructureFactor(zoomedIMGFFT, 10, 20, 180, 75, 2);
|
||||||
|
|
||||||
% Capture the current frame and write it to the video
|
plot(theta_vals/pi, S_theta,'Linewidth',2);
|
||||||
frame = getframe(gcf); % Capture the current figure as a frame
|
set(gca, 'FontSize', 14); % For tick labels only
|
||||||
writeVideo(videoFile, frame); % Write the frame to the video
|
hXLabel = xlabel('\theta (\pi)', 'Interpreter', 'tex');
|
||||||
end
|
hYLabel = ylabel('S(\theta)', 'Interpreter', 'tex');
|
||||||
|
hTitle = title('Angular Structure Factor', 'Interpreter', 'tex');
|
||||||
|
set([hXLabel, hYLabel, hL, hText], 'FontName', font)
|
||||||
|
set([hXLabel, hYLabel, hL], 'FontSize', 14)
|
||||||
|
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
||||||
|
grid on
|
||||||
|
|
||||||
% Close the video file
|
|
||||||
close(videoFile);
|
|
||||||
|
|
||||||
%% Averaged FFT
|
|
||||||
% Assuming od_imgs is a cell array of size 4*n
|
|
||||||
n = length(fft_imgs) / 4; % Calculate n
|
|
||||||
fft_imgs_avg = cell(1, n); % Initialize the new cell array to hold the averaged images
|
|
||||||
|
|
||||||
for i = 1:n
|
|
||||||
% Take the 4 corresponding images from od_imgs
|
|
||||||
img1 = fft_imgs{4*i-3}; % 1st image in the group
|
|
||||||
img2 = fft_imgs{4*i-2}; % 2nd image in the group
|
|
||||||
img3 = fft_imgs{4*i-1}; % 3rd image in the group
|
|
||||||
img4 = fft_imgs{4*i}; % 4th image in the group
|
|
||||||
|
|
||||||
% Compute the average of these 4 images
|
|
||||||
avg_img = (img1 + img2 + img3 + img4) / 4;
|
|
||||||
|
|
||||||
% Store the averaged image in the new cell array
|
|
||||||
fft_imgs_avg{i} = avg_img;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Create VideoWriter object for movie
|
|
||||||
videoFile = VideoWriter('Averaged_FFT.avi', 'Motion JPEG AVI');
|
|
||||||
videoFile.FrameRate = 2; % Set the frame rate (frames per second)
|
|
||||||
open(videoFile); % Open the video file to write
|
|
||||||
|
|
||||||
figure(3)
|
|
||||||
clf
|
|
||||||
set(gcf,'Position',[50 50 950 750])
|
|
||||||
|
|
||||||
% Display the cropped image
|
|
||||||
for k = 1 : length(fft_imgs_avg)
|
|
||||||
imagesc(log(1 + fft_imgs_avg{k}));
|
|
||||||
% Define normalized positions (relative to axis limits)
|
|
||||||
x_offset = 0.025; % 5% offset from the edges
|
|
||||||
y_offset = 0.025; % 5% offset from the edges
|
|
||||||
% Top-right corner (normalized axis coordinates)
|
|
||||||
text(1 - x_offset, 1 - y_offset, ['Angle: ', num2str(theta_values(k), '%.1f')], ...
|
|
||||||
'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
|
||||||
axis equal tight;
|
|
||||||
hcb = colorbar;
|
|
||||||
set(gca,'YDir','normal')
|
|
||||||
xlabel('X', 'Interpreter', 'tex','FontSize',16);
|
|
||||||
ylabel('Y', 'Interpreter', 'tex','FontSize',16);
|
|
||||||
title('Averaged Fourier Power Spectrum','FontSize',16);
|
|
||||||
|
|
||||||
drawnow
|
drawnow
|
||||||
pause(0.5)
|
pause(0.5)
|
||||||
@ -271,7 +226,8 @@ function [IMGFFT, IMGBIN] = computeFourierTransform(I)
|
|||||||
% F_mag - 2D Fourier power spectrum (shifted)
|
% F_mag - 2D Fourier power spectrum (shifted)
|
||||||
|
|
||||||
% Preprocessing: Denoise
|
% Preprocessing: Denoise
|
||||||
I_filt = imgaussfilt(I, 1); % adjust sigma as needed
|
filtered = imgaussfilt(I, 10);
|
||||||
|
I_filt = I - filtered; % adjust sigma as needed
|
||||||
|
|
||||||
% Elliptical mask parameters
|
% Elliptical mask parameters
|
||||||
[rows, cols] = size(I_filt);
|
[rows, cols] = size(I_filt);
|
||||||
@ -304,12 +260,15 @@ function [IMGFFT, IMGBIN] = computeFourierTransform(I)
|
|||||||
I_masked = I_filt .* ellipseMask;
|
I_masked = I_filt .* ellipseMask;
|
||||||
|
|
||||||
% Apply global intensity threshold mask
|
% Apply global intensity threshold mask
|
||||||
intensity_thresh = 0.8;
|
intensity_thresh = 0.20;
|
||||||
intensity_mask = I_masked > intensity_thresh;
|
intensity_mask = I_masked > intensity_thresh;
|
||||||
I_masked = I_masked .* intensity_mask;
|
I_masked = I_masked .* intensity_mask;
|
||||||
|
|
||||||
% Adaptive binarization
|
% Adaptive binarization and cleanup
|
||||||
IMGBIN = imbinarize(I_masked, 'adaptive', 'Sensitivity', 0.0);
|
IMGBIN = imbinarize(I_masked, 'adaptive', 'Sensitivity', 0.0);
|
||||||
|
IMGBIN = imdilate(IMGBIN, strel('disk', 2));
|
||||||
|
IMGBIN = imerode(IMGBIN, strel('disk', 1));
|
||||||
|
IMGBIN = imfill(IMGBIN, 'holes');
|
||||||
|
|
||||||
% Compute 2D Fourier Transform
|
% Compute 2D Fourier Transform
|
||||||
F = fft2(double(I));
|
F = fft2(double(I));
|
||||||
@ -333,6 +292,58 @@ function [IMGFFT, IMGBIN] = computeFourierTransform(I)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function [theta_vals, S_theta] = computeAngularStructureFactor(IMGFFT, r_min, r_max, num_bins, threshold, sigma)
|
||||||
|
% Apply threshold to isolate strong peaks
|
||||||
|
IMGFFT(IMGFFT < threshold) = 0;
|
||||||
|
|
||||||
|
% Prepare polar coordinates
|
||||||
|
[ny, nx] = size(IMGFFT);
|
||||||
|
[X, Y] = meshgrid(1:nx, 1:ny);
|
||||||
|
cx = ceil(nx/2);
|
||||||
|
cy = ceil(ny/2);
|
||||||
|
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
||||||
|
Theta = atan2(Y - cy, X - cx); % range [-pi, pi]
|
||||||
|
|
||||||
|
% Choose radial band
|
||||||
|
radial_mask = (R >= r_min) & (R <= r_max);
|
||||||
|
|
||||||
|
% Initialize the angular structure factor array
|
||||||
|
S_theta = zeros(1, num_bins); % Pre-allocate for 180 angle bins
|
||||||
|
% Define the angle values for the x-axis
|
||||||
|
theta_vals = linspace(0, pi, num_bins);
|
||||||
|
|
||||||
|
% Loop through each angle bin
|
||||||
|
for i = 1:180
|
||||||
|
angle_start = (i-1) * pi / num_bins;
|
||||||
|
angle_end = i * pi / num_bins;
|
||||||
|
|
||||||
|
% Define a mask for the given angle range
|
||||||
|
angle_mask = (Theta >= angle_start & Theta < angle_end);
|
||||||
|
|
||||||
|
bin_mask = radial_mask & angle_mask;
|
||||||
|
|
||||||
|
% Extract the Fourier components for the given angle
|
||||||
|
fft_angle = IMGFFT .* bin_mask;
|
||||||
|
|
||||||
|
% Integrate the Fourier components over the radius at the angle
|
||||||
|
S_theta(i) = sum(sum(abs(fft_angle).^2)); % Compute structure factor (sum of squared magnitudes)
|
||||||
|
end
|
||||||
|
|
||||||
|
% Create a 1D Gaussian kernel
|
||||||
|
half_width = ceil(3 * sigma);
|
||||||
|
x = -half_width:half_width;
|
||||||
|
gauss_kernel = exp(-x.^2 / (2 * sigma^2));
|
||||||
|
gauss_kernel = gauss_kernel / sum(gauss_kernel); % normalize
|
||||||
|
|
||||||
|
% Apply convolution (circular padding to preserve periodicity)
|
||||||
|
S_theta = conv([S_theta(end-half_width+1:end), S_theta, S_theta(1:half_width)], gauss_kernel, 'same');
|
||||||
|
S_theta = S_theta(half_width+1:end-half_width); % crop back to original size
|
||||||
|
|
||||||
|
% Normalize to maximum value of 1
|
||||||
|
S_theta = S_theta / max(S_theta);
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
||||||
% image must be a 2D numerical array
|
% image must be a 2D numerical array
|
||||||
[dim1, dim2] = size(img);
|
[dim1, dim2] = size(img);
|
||||||
@ -475,3 +486,147 @@ function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% Deprecated
|
||||||
|
%% Display Images
|
||||||
|
%{
|
||||||
|
figure(1)
|
||||||
|
clf
|
||||||
|
set(gcf,'Position',[50 50 950 750])
|
||||||
|
|
||||||
|
% Calculate the x and y limits for the cropped image
|
||||||
|
y_min = center(1) - span(2) / 2;
|
||||||
|
y_max = center(1) + span(2) / 2;
|
||||||
|
x_min = center(2) - span(1) / 2;
|
||||||
|
x_max = center(2) + span(1) / 2;
|
||||||
|
|
||||||
|
% Generate x and y arrays representing the original coordinates for each pixel
|
||||||
|
x_range = linspace(x_min, x_max, span(1));
|
||||||
|
y_range = linspace(y_min, y_max, span(2));
|
||||||
|
|
||||||
|
% Display the cropped image
|
||||||
|
for k = 1 : length(od_imgs)
|
||||||
|
imagesc(x_range, y_range, od_imgs{k})
|
||||||
|
axis equal tight;
|
||||||
|
hcb = colorbar;
|
||||||
|
hL = ylabel(hcb, 'Optical Density');
|
||||||
|
set(hL,'Rotation',-90);
|
||||||
|
colormap jet;
|
||||||
|
set(gca,'CLim',[0 3.0]);
|
||||||
|
set(gca,'YDir','normal')
|
||||||
|
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
||||||
|
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
||||||
|
xlabel('X', 'Interpreter', 'tex');
|
||||||
|
ylabel('Y', 'Interpreter', 'tex');
|
||||||
|
|
||||||
|
drawnow
|
||||||
|
pause(0.5)
|
||||||
|
end
|
||||||
|
|
||||||
|
%}
|
||||||
|
%% Averaged FFT
|
||||||
|
%{
|
||||||
|
|
||||||
|
% Assuming od_imgs is a cell array of size 4*n
|
||||||
|
n = length(fft_imgs) / 4; % Calculate n
|
||||||
|
fft_imgs_avg = cell(1, n); % Initialize the new cell array to hold the averaged images
|
||||||
|
|
||||||
|
for i = 1:n
|
||||||
|
% Take the 4 corresponding images from od_imgs
|
||||||
|
img1 = fft_imgs{4*i-3}; % 1st image in the group
|
||||||
|
img2 = fft_imgs{4*i-2}; % 2nd image in the group
|
||||||
|
img3 = fft_imgs{4*i-1}; % 3rd image in the group
|
||||||
|
img4 = fft_imgs{4*i}; % 4th image in the group
|
||||||
|
|
||||||
|
% Compute the average of these 4 images
|
||||||
|
avg_img = (img1 + img2 + img3 + img4) / 4;
|
||||||
|
|
||||||
|
% Store the averaged image in the new cell array
|
||||||
|
fft_imgs_avg{i} = avg_img;
|
||||||
|
end
|
||||||
|
|
||||||
|
% Create VideoWriter object for movie
|
||||||
|
videoFile = VideoWriter('Averaged_FFT.mp4', 'MPEG-4');
|
||||||
|
videoFile.Quality = 100; % Set quality to maximum (0–100)
|
||||||
|
videoFile.FrameRate = 2; % Set the frame rate (frames per second)
|
||||||
|
open(videoFile); % Open the video file to write
|
||||||
|
|
||||||
|
% Display the cropped image
|
||||||
|
for k = 1 : length(fft_imgs_avg)
|
||||||
|
figure(3)
|
||||||
|
clf
|
||||||
|
set(gcf,'Position',[50 50 1500 550])
|
||||||
|
set(gca,'FontSize',16,'Box','On','Linewidth',2);
|
||||||
|
t = tiledlayout(1, 2, 'TileSpacing', 'compact', 'Padding', 'compact'); % 1x2 grid
|
||||||
|
|
||||||
|
nexttile
|
||||||
|
imagesc(log(1 + fft_imgs_avg{k}));
|
||||||
|
% Define normalized positions (relative to axis limits)
|
||||||
|
x_offset = 0.025; % 5% offset from the edges
|
||||||
|
y_offset = 0.025; % 5% offset from the edges
|
||||||
|
% Top-right corner (normalized axis coordinates)
|
||||||
|
text(1 - x_offset, 1 - y_offset, ['Angle: ', num2str(theta_values(k), '%.1f')], ...
|
||||||
|
'Color', 'white', 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontSize', 20, 'Units', 'normalized', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
||||||
|
axis equal tight;
|
||||||
|
hcb = colorbar;
|
||||||
|
set(gca,'YDir','normal')
|
||||||
|
xlabel('X', 'Interpreter', 'tex','FontSize',16);
|
||||||
|
ylabel('Y', 'Interpreter', 'tex','FontSize',16);
|
||||||
|
title('Averaged Fourier Power Spectrum','FontSize',16);
|
||||||
|
|
||||||
|
|
||||||
|
% Plot the angular structure factor
|
||||||
|
nexttile
|
||||||
|
[theta_vals, angular_intensity] = computeAngularDistribution(fft_imgs_avg{k}, 10, 20, 100, 75);
|
||||||
|
polarhistogram('BinEdges', theta_vals, 'BinCounts', angular_intensity, ...
|
||||||
|
'FaceColor', [0.2 0.6 0.9], 'EdgeColor', 'k');
|
||||||
|
title('Angular Distribution');
|
||||||
|
|
||||||
|
drawnow
|
||||||
|
pause(0.5)
|
||||||
|
|
||||||
|
% Capture the current frame and write it to the video
|
||||||
|
frame = getframe(gcf); % Capture the current figure as a frame
|
||||||
|
writeVideo(videoFile, frame); % Write the frame to the video
|
||||||
|
end
|
||||||
|
|
||||||
|
% Close the video file
|
||||||
|
close(videoFile);
|
||||||
|
|
||||||
|
%}
|
||||||
|
%% Angular Distribution
|
||||||
|
%{
|
||||||
|
|
||||||
|
function [theta_vals, angular_intensity] = computeAngularDistribution(IMGFFT, r_min, r_max, num_bins, threshold)
|
||||||
|
|
||||||
|
% Apply threshold to isolate strong peaks
|
||||||
|
IMGFFT(IMGFFT < threshold) = 0;
|
||||||
|
|
||||||
|
% Prepare polar coordinates
|
||||||
|
[ny, nx] = size(IMGFFT);
|
||||||
|
[X, Y] = meshgrid(1:nx, 1:ny);
|
||||||
|
cx = ceil(nx/2);
|
||||||
|
cy = ceil(ny/2);
|
||||||
|
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
||||||
|
Theta = atan2(Y - cy, X - cx); % range [-pi, pi]
|
||||||
|
|
||||||
|
% Choose radial band
|
||||||
|
mask = (R >= r_min) & (R <= r_max);
|
||||||
|
|
||||||
|
% Bin intensities by angle
|
||||||
|
theta_vals = linspace(-pi, pi, num_bins+1);
|
||||||
|
angular_intensity = zeros(1, num_bins);
|
||||||
|
|
||||||
|
for i = 1:num_bins
|
||||||
|
t0 = theta_vals(i);
|
||||||
|
t1 = theta_vals(i+1);
|
||||||
|
bin_mask = mask & (Theta >= t0) & (Theta < t1);
|
||||||
|
tmp = mean(IMGFFT(bin_mask), 'all');
|
||||||
|
if tmp > 50
|
||||||
|
angular_intensity(i) = tmp;
|
||||||
|
else
|
||||||
|
angular_intensity(i) = 0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
%}
|
@ -2,24 +2,26 @@
|
|||||||
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", "/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", "/images/Vertical_Axis_Camera/in_situ_absorption"];
|
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", "/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", "/images/Vertical_Axis_Camera/in_situ_absorption"];
|
||||||
|
|
||||||
%{
|
|
||||||
|
|
||||||
folderPath = "C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/";
|
folderPath = "C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/";
|
||||||
|
|
||||||
run = '0140';
|
run = '0013';
|
||||||
|
|
||||||
cam = 4;
|
folderPath = strcat(folderPath, run);
|
||||||
|
|
||||||
|
cam = 5;
|
||||||
|
|
||||||
angle = 0;
|
angle = 0;
|
||||||
center = [95, 1042];
|
center = [1285, 2105];
|
||||||
span = [50, 50];
|
span = [200, 200];
|
||||||
fraction = [0.1, 0.1];
|
fraction = [0.1, 0.1];
|
||||||
|
|
||||||
pixel_size = 5.86e-6;
|
pixel_size = 5.86e-6;
|
||||||
removeFringes = false;
|
removeFringes = false;
|
||||||
|
|
||||||
%}
|
|
||||||
|
|
||||||
|
%{
|
||||||
folderPath = "C:/Users/Karthik/Documents/GitRepositories/Calculations/Imaging-Response-Function-Extractor/";
|
folderPath = "C:/Users/Karthik/Documents/GitRepositories/Calculations/Imaging-Response-Function-Extractor/";
|
||||||
|
|
||||||
run = '0096';
|
run = '0096';
|
||||||
@ -35,15 +37,16 @@ fraction = [0.1, 0.1];
|
|||||||
|
|
||||||
pixel_size = 5.86e-6;
|
pixel_size = 5.86e-6;
|
||||||
removeFringes = false;
|
removeFringes = false;
|
||||||
|
%}
|
||||||
|
|
||||||
% Compute OD image, rotate and extract ROI for analysis
|
%% Compute OD image, rotate and extract ROI for analysis
|
||||||
% Get a list of all files in the folder with the desired file name pattern.
|
% Get a list of all files in the folder with the desired file name pattern.
|
||||||
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
filePattern = fullfile(folderPath, '*.h5');
|
||||||
files = dir(filePattern);
|
files = dir(filePattern);
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
||||||
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
for k = 1 : length(files)
|
||||||
baseFileName = files(k).name;
|
baseFileName = files(k).name;
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
fullFileName = fullfile(files(k).folder, baseFileName);
|
||||||
@ -60,6 +63,7 @@ for k = 1 : length(files)
|
|||||||
end
|
end
|
||||||
|
|
||||||
% Fringe removal
|
% Fringe removal
|
||||||
|
|
||||||
if removeFringes
|
if removeFringes
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
optrefimages = removefringesInImage(absimages, refimages);
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
||||||
@ -70,14 +74,13 @@ if removeFringes
|
|||||||
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nimgs = size(absimages,3);
|
nimgs = size(absimages(:, :, :),3);
|
||||||
od_imgs = cell(1, nimgs);
|
od_imgs = cell(1, nimgs);
|
||||||
for i = 1:nimgs
|
for i = 1:nimgs
|
||||||
od_imgs{i} = absimages(:, :, i);
|
od_imgs{i} = absimages(:, :, i);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
%% Display Images
|
||||||
%%
|
|
||||||
|
|
||||||
figure(1)
|
figure(1)
|
||||||
clf
|
clf
|
||||||
@ -98,10 +101,10 @@ for k = 1 : length(od_imgs)
|
|||||||
imagesc(x_range, y_range, od_imgs{k})
|
imagesc(x_range, y_range, od_imgs{k})
|
||||||
axis equal tight;
|
axis equal tight;
|
||||||
hcb = colorbar;
|
hcb = colorbar;
|
||||||
hL = ylabel(hcb, 'Normalised Optical Density', 'FontSize', 16);
|
hL = ylabel(hcb, 'Optical Density', 'FontSize', 16);
|
||||||
set(hL,'Rotation',-90);
|
set(hL,'Rotation',-90);
|
||||||
colormap jet;
|
colormap jet;
|
||||||
set(gca,'CLim',[0 1.0]);
|
set(gca,'CLim',[0 3.0]);
|
||||||
set(gca,'YDir','normal')
|
set(gca,'YDir','normal')
|
||||||
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
set(gca, 'YTick', linspace(y_min, y_max, 5)); % Define y ticks
|
||||||
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
set(gca, 'YTickLabel', flip(linspace(y_min, y_max, 5))); % Flip only the labels
|
||||||
@ -112,6 +115,7 @@ for k = 1 : length(od_imgs)
|
|||||||
pause(0.5)
|
pause(0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
%% Overlay images
|
%% Overlay images
|
||||||
|
|
||||||
% image_below = ;
|
% image_below = ;
|
||||||
|
Loading…
Reference in New Issue
Block a user