I am working with fluorescence microscopy images of blood vessels in the brain, stored as HDF5 files (.h5
). My goal is to extract vessel dimensions (diameters) from each frame in a time series and analyze how they change over time.
Currently, I am using MATLAB to:
- Load the
.h5
file and extract individual frames. - Apply Gaussian filtering and contrast enhancement to improve vessel visibility.
- Perform edge detection (Canny) and skeletonization to extract vessel centerlines.
- Compute vessel diameters using the Euclidean distance transform from the skeleton.
However, I am running into several issues:
- Edge detection is inconsistent and picks up artifacts inside the vessel.
- The skeleton sometimes extends beyond the vessels or is not continuous.
- Extracted diameters appear constant, even when the vessel visibly changes size.
Working example of an h5 frame
Current Approach in MATLAB
Here’s the code I am using to manually select vessels and compute diameters:
% Load a single frame from HDF5 file
frame = double(h5read('file.h5', '/recording', [1,1,1,1000], [512,512,1,1]));
% Preprocessing: Smoothing & contrast enhancement
frame = imgaussfilt(frame, 2);
frame = imadjust(mat2gray(frame), stretchlim(mat2gray(frame), [0.01, 0.99]));
% Edge detection & binarization
bw = imbinarize(frame, 'adaptive', 'Sensitivity', 0.5);
bw = bwareaopen(bw, 50);
% Skeletonization & distance transform
skeleton = bwskel(bw);
distance_map = bwdist(~bw);
diameter_map = distance_map * 2;
% Extract diameters along the skeleton
[y, x] = find(skeleton);
diameters = arrayfun(@(i) diameter_map(y(i), x(i)), 1:length(x));
% Plot results
figure;
imshow(frame, []); hold on;
scatter(x, y, 15, diameters, 'filled'); % Color vessels by width
colormap(jet); colorbar;
title('Vessel Skeleton & Diameters');
% Diameter profile plot
figure;
plot(diameters, 'b.-');
xlabel('Skeleton Point Index');
ylabel('Vessel Diameter (pixels)');
title('Vessel Diameter Profile');
Resulting edges and vessel diameter detection
As you can see, the edges are picked up but not always, and the diameters are calculated on no real basis. They don’t seem to be particularly telling.
Question:
- How can I ensure accurate edge detection that captures the actual vessel boundaries and calculate their diameters?