StereoFractAnalyzer Function Reference

__init__(self, stl_path=None, img_path=None)

Initializes a StereoFractAnalyzer instance with optional paths to an STL file and an image file.

Parameters:

Example:

# Initialize without any paths
analyzer = StereoFractAnalyzer()

# Initialize with an STL path
analyzer = StereoFractAnalyzer(stl_path="path/to/model.stl")

transform(self, translation=(0,0,0), rotation=(0,0,0), scale=1.0)

Applies geometric transformations to the loaded 3D mesh. This includes translation, rotation, and scaling.

Parameters:

Example:

# 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)

3D Mesh Analysis

transform

Applies geometric transformations to the 3D mesh, including translation, rotation, and scaling.

Parameters:

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)

get_voxel

Converts the 3D mesh into a voxel grid representation, enabling volumetric analysis of the structure.

Parameters:

Example:

# Generate a voxel grid with voxel size 0.5
voxel_grid = analyzer.get_voxel(size=0.5)

view

Visualizes the 3D mesh or a point cloud representation of the mesh associated with the StereoFractAnalyzer instance.

Parameters:

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)

2D Image Analysis

box_count_image

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:

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)

get_image_fractal_dimension

Calculates and optionally plots the fractal dimension of a 2D image using the box counting method.

Parameters:

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)

Utility Methods

calculate_intersection_point

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:

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)

calculate_slice

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:

Example:

# Calculate a horizontal slice of the mesh at z-height = 5
slice_lines = analyzer.calculate_slice(analyzer.STL, 5)
print(slice_lines)

box_counting

Estimates the fractal dimension of a dataset using the box counting method, applicable to both 3D surfaces and 2D projections.

Parameters:

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}")

calculate_slice

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:

Example:

# Calculate a horizontal slice of the mesh at z-height = 5
slice_lines = analyzer.calculate_slice(analyzer.STL, 5)
print(slice_lines)

box_counting

Estimates the fractal dimension of a dataset using the box counting method, a key technique in fractal geometry.

Parameters:

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}")

draw_contours

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:

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)

get_contour_fractal_dimension

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:

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}")

get_surface_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:

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}")

calculate_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)

Contributing

Contributions to StereoFractAnalyzer are welcome! Please refer to the project's repository for contributing guidelines.

License

StereoFractAnalyzer is licensed under the MIT License. See the LICENSE file in the project repository for full details.

Contact

For support or to provide feedback, please contact the package maintainer at kmmukut@gmail.com.