-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGen_Diff.m
More file actions
59 lines (42 loc) · 1.42 KB
/
Copy pathGen_Diff.m
File metadata and controls
59 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
clc; clear; close all;
%% ================= USER INPUT =================
folder = 'C:\Users\ADITYA\Downloads\Exp Data\Aman\frames'; % <<< CHANGE
chunkSize = 2000;
%% =============================================
files = dir(fullfile(folder,'*.tif'));
files = {files.name};
N = numel(files);
fprintf('Frames detected: %d\n',N);
I0 = im2double(imread(fullfile(folder,files{1})));
if size(I0,3)==3, I0 = rgb2gray(I0); end
[H,W] = size(I0);
GD = zeros(H,W);
pairs = N - 1;
fprintf('Computing GD map\n');
for k = 1:chunkSize:pairs
k_end = min(k+chunkSize-1,pairs);
for kk = k:k_end
I1 = im2double(imread(fullfile(folder,files{kk})));
I2 = im2double(imread(fullfile(folder,files{kk+1})));
if size(I1,3)==3, I1 = rgb2gray(I1); end
if size(I2,3)==3, I2 = rgb2gray(I2); end
GD = GD + abs(I1 - I2);
end
end
fprintf('GD computation completed.\n');
%% ---- Save ----
outdir = fullfile(folder,'Simple_GD_Output');
if ~exist(outdir,'dir'), mkdir(outdir); end
vmin = prctile(GD(:),2);
vmax = prctile(GD(:),98);
Gn = (GD - vmin) / (vmax - vmin + eps);
Gn = min(max(Gn,0),1);
imwrite(Gn, fullfile(outdir,'GD_gray.png'));
figure('Visible','off');
imagesc(GD); axis image off;
colormap(jet); colorbar;
title('GD Map');
saveas(gcf, fullfile(outdir,'GD_color.png'));
close;
save(fullfile(outdir,'GD.mat'),'GD');
fprintf('✅ GD map saved.\n');