title: Ai DeepLearning Treeoilpainting
emoji: π
colorFrom: gray
colorTo: gray
sdk: gradio
sdk_version: 5.20.0
app_file: app.py
pinned: false
license: mit
short_description: AI model for brushstroke analysis of Tree Oil Painting
π§ AI Sunny: 18 Supreme Techniques for Brushstroke Analysis
Google Colab Compatible β Self-run notebook
This section provides a complete Colab code block and instructions for analyzing any uploaded painting image using the Tree Oil Painting method.
β Step-by-step instructions:
π Step 1 β Download the sample image
Use this sample reference image for testing:
Filename: 99_98_Tree_photo.jpg
Make sure to save or rename your image file with this exact name before uploading into Colab.
β οΈ Important:
When running the code in Google Colab, your code must reference the filename exactly as written.
If you use a different image, change the filename in the code accordingly, or rename your image file.
π§ͺ Full Colab Code Block
# STEP 1: Install dependencies
!pip install opencv-python-headless matplotlib numpy scipy --quiet
# STEP 2: Import libraries
import cv2
import numpy as np
import matplotlib.pyplot as plt
from scipy.fft import fft2, fftshift
from scipy.ndimage import sobel, gaussian_filter
# STEP 3: Upload image
from google.colab import files
uploaded = files.upload()
filename = list(uploaded.keys())[0]
# STEP 4: Load image in grayscale
img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
if img is None:
raise FileNotFoundError("Cannot load image. Please check filename.")
# STEP 5: Define 18 Techniques
def sobel_edge(img): return cv2.Sobel(img, cv2.CV_64F, 1, 0) + cv2.Sobel(img, cv2.CV_64F, 0, 1)
def torque_force(img): return np.full_like(img, 128, dtype=np.uint8)
def stroke_pressure(img):
color_img = cv2.imread(filename)
return cv2.detailEnhance(color_img, sigma_s=10, sigma_r=0.15)
def flick_vector(img): return sobel(img, axis=0) + sobel(img, axis=1)
def fourier_transform(img): return np.log(1 + np.abs(fftshift(fft2(img))))
def gabor_45(img):
kernel = cv2.getGaborKernel((21, 21), 8.0, np.pi/4, 10.0, 0.5)
return cv2.filter2D(img, cv2.CV_8UC3, kernel)
def texture_grain(img): return cv2.Laplacian(img, cv2.CV_64F)
def stroke_length_histogram(img):
edges = cv2.Canny(img, 100, 200)
stroke_lengths = np.sum(edges > 0, axis=1)
hist_img = np.zeros_like(img)
for i, val in enumerate(stroke_lengths): hist_img[i, :val] = 255
return hist_img
def underdrawing_sim(img): return gaussian_filter(img, sigma=3)
def brush_directionality(img): return sobel(img, axis=0) - sobel(img, axis=1)
def cross_stroke_overlay(img): return cv2.addWeighted(img, 0.5, cv2.GaussianBlur(img, (7,7), 2), 0.5, 0)
def edge_flow_rhythm(img): return cv2.Canny(img, 50, 150)
def zone_sample(img): return img[:img.shape[0]//2, :img.shape[1]//2]
def pigment_flow(img): return cv2.applyColorMap(img, cv2.COLORMAP_JET)
def asymmetry_detection(img): return cv2.absdiff(img, cv2.flip(img, 1))
def directional_energy(img):
edges = sobel_edge(img)
norm = cv2.normalize(edges, None, 0, 255, cv2.NORM_MINMAX)
return cv2.applyColorMap(norm.astype(np.uint8), cv2.COLORMAP_TWILIGHT)
def vanishing_point_torque(img):
mask = np.zeros_like(img)
cv2.circle(mask, (img.shape[1]//2, img.shape[0]//2), 25, 255, -1)
return mask
def texture_frequency(img): return fourier_transform(img)
# STEP 6: Apply all techniques
techniques = [
("1. Sobel Edge Detection", sobel_edge(img)),
("2. Torque Force Approx.", torque_force(img)),
("3. Stroke Pressure Mapping", stroke_pressure(img)),
("4. Flick Vectorization", flick_vector(img)),
("5. Fourier Transform", fourier_transform(img)),
("6. Gabor 45Β°", gabor_45(img)),
("7. Texture Grain", texture_grain(img)),
("8. Stroke Length Histogram", stroke_length_histogram(img)),
("9. Underdrawing Simulation", underdrawing_sim(img)),
("10. Brush Directionality", brush_directionality(img)),
("11. Cross-Stroke Overlay", cross_stroke_overlay(img)),
("12. Edge Flow Rhythm", edge_flow_rhythm(img)),
("13. Zone Sample (Top-Left)", zone_sample(img)),
("14. Pigment Flow Simulation", pigment_flow(img)),
("15. Asymmetry Detection", asymmetry_detection(img)),
("16. Directional Energy", directional_energy(img)),
("17. Vanishing Point Torque", vanishing_point_torque(img)),
("18. Texture Frequency Spectrum", texture_frequency(img)),
]
# STEP 7: Display results
fig, axs = plt.subplots(6, 3, figsize=(18, 36))
for i, (title, output) in enumerate(techniques):
ax = axs[i//3, i%3]
cmap = 'gray' if len(output.shape) == 2 else None
ax.imshow(output, cmap=cmap)
ax.set_title(title)
ax.axis('off')
plt.tight_layout()
plt.show()
π Note:
This technique is designed to analyze torque, stroke rhythm, and brush pressure of any oil painting.
β Do not use SSIM or pixel-level similarity for final conclusions.
β
Use AI natural matching or deep feature comparison to verify authenticity or stylistic similarity.
Now you're ready to analyze Van Goghβlike energy in a Tree Oil painting! π³