Hydraulic Diameter Calculation Tool

Version 1.0.0 (335 KB) by Kshitij
MATLAB tool to calculate the hydraulic diameter of arbitrary shapes in images using automated image processing.
6 Downloads
Updated 20 Feb 2025

View License

This MATLAB tool calculates the hydraulic diameter of arbitrary shapes in an image using automated image processing. The script processes the input image by converting it to grayscale, enhancing contrast, and applying binarization. Users are required to adjust the binarization threshold value (imbinarize) to ensure a clear outline of the shape's filled region. The tool then performs morphological operations, fills holes, and removes small noise to isolate distinct shapes.
The connected regions are labeled, and their geometric properties (area, perimeter) are measured. The hydraulic diameter is computed using the formula:
D_H=4A/P
Results are displayed on a labeled binary image and a color-coded labeled image for easy visualization. A table summarizing the area, perimeter, and hydraulic diameter in calibrated units (e.g., mm) is also printed.
Instructions for Use:
1. Replace 'Replace.jpg' with the path to your input image in the script.
img = imread('Replace.jpg');
2. Modify the binarization threshold value in imbinarize(gray_img, threshold) until you achieve a clear outline of the shape's filled region.
binary_img = imbinarize(gray_img, 0.15);
3. Adjust the scale variable to match your pixel-to-mm calibration factor.
scale = 67; % Pixels/mm - VERIFY THIS CALIBRATION!
4. Run the script to process the image and compute hydraulic diameters for all detected shapes.
Review results in the generated labeled images and output table.
This tool is ideal for researchers and engineers working in fluid dynamics, microfluidics, or any field requiring precise hydraulic diameter measurements from images of arbitrary shapes.
Let me know if you'd like further refinements!

Cite As

Kshitij (2025). Hydraulic Diameter Calculation Tool (https://www.mathworks.com/matlabcentral/fileexchange/180192-hydraulic-diameter-calculation-tool), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2024b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0