Image Acquisition Code for Cantilever Training Model

Python

Sample: The specimen to be measured (if too close, sample color may mix with the background) (Distance from sample: 2000um) - Air: empty space, Rubber: dark, non-reflective, Wafer: bright, reflective - Cantilever: provided by RAT from group 1 - Vision: Auto Exposure ON, Contrast 10%, LED [-20, 0, 20] (set 0 to the point where cantilever texture is visible) - Defocus: -200~200um, acquired in 10um steps (labeling performed only for -100~100um)

main 1 file
Image Acquisition Code …..py
data_acquisition.py 2.4 KB
Image Acquisition Code …..py 1220 bytes
import numpy as np
from SmartRemote import SmartRemote as SR 
import os
import afm2
from tqdm import tqdm

PATH = 'data//0327'
cantliever = 'PPP-NCHAu'
location = 'air'

target_path = os.path.join(os.getcwd(), PATH, f'{cantliever}_{location}')
os.makedirs(target_path, exist_ok=True)

on_focus_f = afm2.get_focus_pos()  # Current focus value manually set for the on-focus condition
delta_light_list = [-20, 0, 20]
default_light = 40

for delta_f in tqdm(np.linspace(-200, 200, 41).astype(int)):
    afm2.move_to_1d_motion('f', on_focus_f + delta_f)

    for delta_light in delta_light_list:
        afm2.set_vision_config(light=default_light + delta_light, exposure=0, contrast=10, autoExposure=True, autoContrast=False, autoWb=True)  # Vision Setting # light=default_light + delta_light, exposure=0, contrast=10, autoExposure=True, autoContrast=False, autoWb=True
        afm2.sleep(1000)
        path_name = f"{cantliever}_defocus_{on_focus_f + delta_f}_led_{default_light + delta_light}_location_{location}.jpg"  
        path_name = os.path.join(target_path, path_name)
        afm2.capture_image(path_name)

afm2.move_to_1d_motion('f', on_focus_f) # Move to the previous on-focus position
Comments (0)

No comments yet. Be the first to comment!

Snippet Information
Author: taehun.yang
Language: Python
Created: Oct 23, 2025
Updated: 0 minutes ago
Views: 34
Stars: 1

Links & Files

Additional Files (1):