Initializes a StereoFractAnalyzer instance with optional paths to an STL file and an image file.
# Initialize without any paths
analyzer = StereoFractAnalyzer()
# Initialize with an STL path
analyzer = StereoFractAnalyzer(stl_path="path/to/model.stl")
Applies geometric transformations to the loaded 3D mesh. This includes translation, rotation, and scaling.
# Translate by (10, 0, 0), rotate by π/4 radians around the Z-axis, and scale by 2
analyzer.transform(translation=(10, 0, 0), rotation=(0, 0, np.pi/4), scale=2)
Applies geometric transformations to the 3D mesh, including translation, rotation, and scaling.
Parameters:
translation
(tuple of float): Specifies the translation vector as (x, y, z).rotation
(tuple of float): Specifies the rotation angles in radians for each of the x, y, and z axes, respectively.scale
(float): Specifies the scaling factor to be applied to the mesh.Example:
# Translate by (10, 5, 0), rotate by 45 degrees around the Z-axis, and scale by 2.0
transformed_mesh = analyzer.transform(translation=(10, 5, 0), rotation=(0, 0, np.pi/4), scale=2.0)
Converts the 3D mesh into a voxel grid representation, enabling volumetric analysis of the structure.
Parameters:
size
(int or float, optional): The edge length of each cubic voxel in the grid. Default is 1.Example:
# Generate a voxel grid with voxel size 0.5
voxel_grid = analyzer.get_voxel(size=0.5)
Visualizes the 3D mesh or a point cloud representation of the mesh associated with the StereoFractAnalyzer instance.
Parameters:
point_cloud_data
(int, optional): The number of points to sample for creating a point cloud representation. Default is 0 (visualize the original mesh).Example:
# Visualize the original 3D mesh
analyzer.view()
# Visualize a point cloud sampled from the mesh with 1000 points
analyzer.view(point_cloud_data=1000)
Calculates the box counts for a binary image to estimate its fractal dimension using the box counting method. This method is applicable for analyzing the complexity of patterns within the image.
Parameters:
img
(PIL.Image.Image): The binary image to be analyzed.min_size
(int, optional): The minimum box size to use in the analysis. Default is 1 pixel.max_size
(int, optional): The maximum box size to use in the analysis. If not specified, it defaults to half of the smallest image dimension.n_sizes
(int, optional): The number of different box sizes to use, distributed logarithmically between min_size and max_size. Default is 10.Example:
# Analyze a binary image for fractal dimension
img = Image.open("path/to/binary_image.png")
sizes, counts = analyzer.box_count_image(img, min_size=1, max_size=100, n_sizes=10)
print(sizes, counts)
Calculates and optionally plots the fractal dimension of a 2D image using the box counting method.
Parameters:
img_path
(str or int, optional): Path to the binary image file. Default is 0 (use image path provided during initialization).plot
(int, optional): If set to 1, the method generates a log-log plot of the box counting analysis. Default is 1.Example:
# Calculate and plot the fractal dimension of an image
fractal_dimension = analyzer.get_image_fractal_dimension("path/to/image.png", plot=1)
print("The fractal dimension is:", fractal_dimension)
Calculates the intersection point between a line segment and a horizontal plane at a given z-height, useful for slicing operations or analyzing spatial relationships within the 3D space.
Parameters:
p1
(tuple or list): The (x, y, z) coordinates of the first point defining the line segment.p2
(tuple or list): The (x, y, z) coordinates of the second point defining the line segment.z_height
(float): The z-coordinate of the horizontal plane with which the intersection is calculated.Example:
# Calculate intersection point of a line with a plane at z-height = 4
p1 = (1, 2, 3)
p2 = (1, 2, 5)
z_height = 4
intersection_point = analyzer.calculate_intersection_point(p1, p2, z_height)
print(intersection_point)
Computes the intersection lines between the mesh and a horizontal plane at the given z-height, useful for generating cross-sections of the mesh.
Parameters:
MESH
(open3d.geometry.TriangleMesh): The 3D mesh from which the slice is to be calculated.z_height
(float): The z-coordinate of the horizontal plane used to slice the mesh.Example:
# Calculate a horizontal slice of the mesh at z-height = 5
slice_lines = analyzer.calculate_slice(analyzer.STL, 5)
print(slice_lines)
Estimates the fractal dimension of a dataset using the box counting method, applicable to both 3D surfaces and 2D projections.
Parameters:
points
(numpy.ndarray): An array of points representing the dataset.min_box_size
(float): The size of the smallest box to use in the analysis.max_box_size
(float): The size of the largest box to use in the analysis.steps
(int): The number of steps between the smallest and largest box sizes, determining the granularity of the analysis.plot
(int, optional): If set to 1, a log-log plot of the box size versus the number of boxes is generated. Default is 0.Example:
# Estimate fractal dimension of a set of 3D points
points = np.random.rand(1000, 3) # Generate some random points
D, sizes, counts = analyzer.box_counting(points, 0.01, 1.0, 10, plot=1)
print(f"Estimated fractal dimension: {D}")
Computes a horizontal slice of the 3D mesh at a specified z-height, useful for analyzing cross-sections of the mesh for further analysis.
Parameters:
MESH
(open3d.geometry.TriangleMesh): The 3D mesh from which the slice is to be calculated.z_height
(float): The z-coordinate of the horizontal plane used to slice the mesh.Example:
# Calculate a horizontal slice of the mesh at z-height = 5
slice_lines = analyzer.calculate_slice(analyzer.STL, 5)
print(slice_lines)
Estimates the fractal dimension of a dataset using the box counting method, a key technique in fractal geometry.
Parameters:
points
(numpy.ndarray): An array of points representing the dataset.min_box_size
(float): The size of the smallest box to use in the analysis.max_box_size
(float): The size of the largest box to use in the analysis.steps
(int): The number of steps between the smallest and largest box sizes.plot
(int, optional): If set to 1, a log-log plot of the box size versus the number of boxes is generated.Example:
# Generate some random points and calculate the fractal dimension
points = np.random.rand(1000, 3) # Example points
D, sizes, counts = analyzer.box_counting(points, 0.01, 1.0, 10, plot=1)
print(f"Estimated fractal dimension: {D}")
Draws the contours of the 3D mesh at different z-heights, which can be crucial for visualizing the shape and features of the mesh across different layers.
Parameters:
zmin
(int or float): The minimum z-height at which to start slicing the mesh.zmax
(int or float): The maximum z-height at which to end slicing the mesh.step
(int or float): The interval between successive z-heights.save
(int, optional): If set to 1, saves each contour plot as an image file.Example:
# Draw and optionally save contour plots for the mesh sliced at specified z-heights
analyzer.draw_contours(zmin=0, zmax=20, step=2, save=1)
Calculates the fractal dimension of a contour slice at a specified z-height within the 3D mesh, providing a quantitative measure of the complexity or roughness of the contour line.
Parameters:
z_height
(float): The z-coordinate of the horizontal plane used to slice the mesh and calculate the fractal dimension.plot
(int, optional): If set to 1, a log-log plot of the box size versus the number of boxes is generated for visual inspection. Default is 0.Example:
# Calculate the fractal dimension of a contour at z-height 5.0
fractal_dimension = analyzer.get_contour_fractal_dimension(5.0, plot=1)
print(f"Fractal dimension of the contour at z=5.0: {fractal_dimension}")
Calculates the fractal dimension of the surface of the 3D mesh by analyzing the complexity of its contour slices at different z-heights, providing a measure of the surface's overall complexity or roughness.
Parameters:
increment
(int or float, optional): The interval between successive z-heights for slicing the mesh. Default is 1.plot
(int, optional): If set to 1, generates a plot for each contour's fractal dimension calculation. Default is 0.Example:
# Calculate the surface fractal dimension of the mesh
surface_fractal_dimension = analyzer.get_surface_fractal_dimension(increment=0.5, plot=1)
print(f"Surface fractal dimension: {surface_fractal_dimension}")
A comprehensive test method to verify the basic functionalities of the StereoFractAnalyzer class related to fractal dimension calculation, including loading meshes and images, transforming geometries, and analyzing fractal dimensions.
Usage: This method does not require specific parameters for invocation and is designed for testing and demonstration purposes.
Example:
# Perform a comprehensive test to verify fractal dimension calculation functionalities
fractal_dimension = analyzer.calculate_fractal_dimension()
print("Calculated fractal dimension:", fractal_dimension)
Contributions to StereoFractAnalyzer are welcome! Please refer to the project's repository for contributing guidelines.
StereoFractAnalyzer is licensed under the MIT License. See the LICENSE file in the project repository for full details.
For support or to provide feedback, please contact the package maintainer at kmmukut@gmail.com.