diff --git a/Config/config.json b/Config/config.json index 7631451..00f98f7 100644 --- a/Config/config.json +++ b/Config/config.json @@ -3,7 +3,7 @@ "Amplitude_mm": 1, "Time_in_beam_s": 5, "Time_out_of_beam_s": 10, - "Exposure_time": 0.0004, + "Exposure_time": 0.0003, "Img_Processing": 1, "pixel_size_mu": 0.275 } \ No newline at end of file diff --git a/Scripts/__pycache__/metrology_functions.cpython-313.pyc b/Scripts/__pycache__/metrology_functions.cpython-313.pyc index 576ca07..dabac19 100644 Binary files a/Scripts/__pycache__/metrology_functions.cpython-313.pyc and b/Scripts/__pycache__/metrology_functions.cpython-313.pyc differ diff --git a/Scripts/metrology_functions.py b/Scripts/metrology_functions.py index ee62b06..570d771 100644 --- a/Scripts/metrology_functions.py +++ b/Scripts/metrology_functions.py @@ -82,13 +82,42 @@ def gaussian_2d(coords, amplitude, x0, y0, sigma_x, sigma_y, offset): return amplitude * np.exp( -(((x - x0) ** 2) / (2 * sigma_x ** 2) + ((y - y0) ** 2) / (2 * sigma_y ** 2)) ) + offset +def band_pass_filter(image, low_radius, high_radius): + # Convert to float32 for FFT + img_float = np.float32(image) + + # Get shape + rows, cols = img_float.shape + crow, ccol = rows // 2 , cols // 2 # center + + # Perform FFT and shift zero frequency to center + f = np.fft.fft2(img_float) + fshift = np.fft.fftshift(f) + + # Create a band-pass mask + mask = np.zeros((rows, cols), np.uint8) + for u in range(rows): + for v in range(cols): + dist = np.sqrt((u - crow)**2 + (v - ccol)**2) + if low_radius < dist < high_radius: + mask[u, v] = 1 + + # Apply mask and inverse FFT + fshift_filtered = fshift * mask + f_ishift = np.fft.ifftshift(fshift_filtered) + img_back = np.fft.ifft2(f_ishift) + img_back = np.abs(img_back) + + return img_back def __process_img(img , retimg=0): + img_np = np.array(img) + img = band_pass_filter(img_np,15,25) img = cv2.GaussianBlur(img,(5,5),0) img = spnd.zoom(img, 4,order=3) z = np.array(img) - # Create a test image (e.g., 2D Gaussian) + """# Create a test image (e.g., 2D Gaussian) x = np.linspace(0, z.shape[0], z.shape[0]) y = np.linspace(0, z.shape[1], z.shape[1]) x, y = np.meshgrid(x, y) @@ -101,8 +130,8 @@ def __process_img(img , retimg=0): popt, _ = curve_fit(gaussian_2d, (x.ravel(), y.ravel()), z.ravel(), p0=initial_guess) x = popt[1] - y = popt[2] - x,y = np.unravel_index(np.argmax(z), z.shape) + y = popt[2]""" + y,x = np.unravel_index(np.argmax(z), z.shape) #ret1, th1 = cv2.threshold(img, 196, 255, cv2.THRESH_BINARY) #x, y = image_center_of_mass(img, plot=False, verbose=False) if retimg: diff --git a/notebooks/sample.ipynb b/notebooks/sample.ipynb index 289f814..fb8c8ce 100644 --- a/notebooks/sample.ipynb +++ b/notebooks/sample.ipynb @@ -87,6 +87,10 @@ "metadata": { "jupyter": { "source_hidden": true + }, + "ExecuteTime": { + "end_time": "2025-07-18T06:52:44.899219Z", + "start_time": "2025-07-18T06:52:44.675052Z" } }, "source": [ @@ -295,8 +299,195 @@ "\n", "\n" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Scripts\n", + "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\config.json\n", + "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\config.json\n", + "Path exists: C:\\Users\\berti_r\\Python_Projects\\templates\\motion_libs\n", + "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\measurement.json\n", + "Constructor for PLC\n", + "Connect to PLC\n", + "is_open()=True\n", + "get_local_address()=None\n", + "read_device_info()=('Plc30 App', )\n", + "GVL_APP.nAXIS_NUM=3\n", + "Constructor for axis\n" + ] + }, + { + "data": { + "text/plain": [ + "Dropdown(description='Test Type:', options=('Image Test', 'Repeatability Test', 'Static Test'), value='Image T…" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "32821ca26005425a9c8732deb7dc87ed" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "a17b77f1308a40a08fdf90784756fe86" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "BoundedIntText(value=10, description='Nr of cycles:', max=1000, min=1)" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "ca9b34140a1b49ac976feaf9eef11b92" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "8f31b3e0d1254f7fae2a3f0df4e5d375" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Text(value='0.0003', description='Exposure [s]:')" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "6da3d9bc3be34c88a6b19957d0d58f35" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "4f986990fc59495dbdb5934387d40120" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "ToggleButton(value=True, description='Processing', tooltip='Toggle processing on/off')" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "d3e8ee7c113940a487f265c1c0b20b08" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "eb679b026bb140d1bd0f3c862cfc9b00" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Button(description='Set exposure time', style=ButtonStyle())" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "cc949c4a1bad410da8289166146a509e" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "583de4908de9490ca46e8f642ab39691" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Button(description='Start Measurement', style=ButtonStyle())" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "97bbe99cd5a843d485f61bc9ea5ecad7" + } + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "6277546bd4a94b41a3dd142175b3b13f" + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "execution_count": 1 }, { "cell_type": "markdown",