DropDetection_Sum
walk_forward(array:np.ndarray, steep:float)
Walk forward from the start index until we find a value greater than 0. Steep: a parameter that defines the steepness of the slope to detect the drop.
Parameters:
array
(np.ndarray): The array to walk through.steep
(float): The steepness of the slope to detect the drop.
Returns:
int
: The index where the drop is detected.Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_walk_forward
backward(array:np.ndarray, steep:float)
Walk forward from the start index until we find a value greater than 0. Steep: a parameter that defines the steepness of the slope to detect the drop.
Parameters:
array
(np.ndarray): The array to walk through.steep
(float): The steepness of the slope to detect the drop.
Returns:
int
: The index where the drop is detected.Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_backward
detect_drop(image:cv2.Mat, dims:tuple[int, int], show:bool, scaleDownFactor_x:int, scaleDownFactory:int)
Trying to detect images with less than 2ms delay. [V] 0. Convert image to grayscale, [V] 1. Resizing image, [V] 2. Applying gaussian blur (morphologyEx worked better than Gaussian blur), [-] 3. Transposing image (Optimization purposes) [Didn't improve any thing and because of if damaged was more than benefits], [V] 4. Summation over rows [-] 5. Normalize images based on height and maximum brightness, [V] 6. Finding beginning of the drop and ending of the drop, and finally drawing a rectangle around the drop.
Parameters:
image
(cv2.Mat): Input image to detect drops.dims
(tuple[int, int]): Dimensions of the input image.show
(bool): Whether to show the processed image and plot the sum of rows.scaleDownFactor_x
(int): Factor to scale down the width of the image.scaleDownFactory
(int): Factor to scale down the height of the image.
Returns:
np.ndarray
: Sum of rows of the processed image.Caution:
Code will fail if there are more than one drop in the image.
Images should have exactly 5 rows of black pixels at the bottom of the image.
It works with tilted setup drop images, on other drop shape it is untested
Todo:
Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_detect_drop
detect_dropV2(image:cv2.Mat, dims:tuple[int, int], show:bool, scaleDownFactor_x:int, scaleDownFactory:int)
Same as V1 but added a version some that has seen the morphologyEx version image. Because if you have small drops in the end side of slide, which is highly probable it confuses the slope and the length of drop will be around 1000 pixels which is cause failure in 4S-SROF and other algorithms.
Parameters:
image
(cv2.Mat): Input image to detect drops.dims
(tuple[int, int]): Dimensions of the input image.show
(bool): Whether to show the processed image and plot the sum of rows.scaleDownFactor_x
(int): Factor to scale down the width of the image.scaleDownFactory
(int): Factor to scale down the height of the image.
Returns:
np.ndarray
: Sum of rows of the processed image.Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_detect_dropV2
extendLength(array:np.ndarray, new_length:int)
Extend the length of the array to a new length by repeating the entire array.
Parameters:
array
(np.ndarray): The input array to extend.new_length
(int): The desired new length of the array.
Returns:
np.ndarray
: The extended array with the new length.Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_extendLength
draw_bounds(image:cv2.Mat, start:int, end:int, scaleDownFactor:int, thickness:int)
Draw a rectangle on the image from start to end. For testing purposes, it draws a rectangle on the image to visualize the detected drop.
Parameters:
image
(cv2.Mat): Input image to draw the rectangle on.start
(int): Starting index of the rectangle.end
(int): Ending index of the rectangle.scaleDownFactor
(int): Factor to scale down the image.thickness
(int): Thickness of the rectangle border.
Returns:

Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_draw_bounds
detection(image:cv2.Mat, scaleDownFactor:int)
Detects the drop in the image by analyzing pixel intensity changes. For testing purposes, it returns the indices of the beginning and end of the drop.
Parameters:
image
(cv2.Mat): Input image to detect drops.scaleDownFactor
(int): Factor to scale down the image for processing.
Returns:
tuple[int, int]
: Indices of the beginning and end of the drop in the image.Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_detection
crop_and_save_image(input_path:str, output_path:str, x1:int, x2:int)
Crops a region from the input image and saves it to the output path.
Parameters:
input_path
(str): Path to the input image.output_path
(str): Path to save the cropped image.x1
(int): Top-left x-coordinate.x2
(int): Bottom-right x-coordinate.
Raises:
ValueError
: If the crop coordinates are invalid or image cannot be loaded.
Examples:
crop_and_save_image("input.jpg", "output.jpg", 10, 20, 100, 200)
Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_crop_and_save_image
Main(experiment:str, SaveAddress:str, SaveAddressCSV:str, extension:str, scaleDownFactor_x:int, drop_width:int, tolerance_width:float, _morphologyEx:bool)
Crops all images for a single experiment folder and saves crop info to CSV.
Parameters:
experiment
(str): Path to the experiment folder containing images.SaveAddress
(str): Optional path to save cropped images.SaveAddressCSV
(str): Optional path to save CSV file with crop info.extension
(str): File extension of images to process (default: '.png').scaleDownFactor_x
(int): Factor to scale down the images for processing.drop_width
(int): Initial width of the drop to be detected. According to my experiment it is usually 150 in beginning and goes up to 450 for drops with surfactant.tolerance_width
(float): Tolerance width for drop detection (default: 1.13)._morphologyEx
(bool): Whether to apply morphologyEx operation on the image (default: False).
Raises:
ValueError
: If no images are found in the experiment folder.ValueError
: If the crop coordinates are invalid.
Examples:
>>> Main("path/to/experiment", "path/to/save/cropped_images", "path/to/save/csv", extension='.png', scaleDownFactor_x=5, drop_width=300, tolerance_width=1.13)
Caution:
Adaptive approach to detect drops in images.
In this function width of the detected drop should be around 300 pixels or 115% of the image width. other wise the steep value will be adjusted to 0.005 from 0.0025. Some time a small drop in the end of slide can be sitting and that is enough to cause problems in the detection. We end up with a really wide image.
Labels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_Main
perfMeasure()
Measure the performance of the drop detection algorithm. This function is a placeholder for performance measurement logic.
Returns:
[detection_perf] Avg peak memory usage
: 158.03 KiBLabels:
src_PyThon_ContactAngle_DropDetection_DropDetection_Sum_perfMeasure