// Low-pass filter in frequency domain [m, n] = size(gray_img); cx = m/2; cy = n/2; radius = 30; H = zeros(m, n); for i = 1:m for j = 1:n if sqrt((i-cx)^2 + (j-cy)^2) <= radius H(i, j) = 1; end end end
// 3. Denoise with median filter img = medfilt2(img, [3 3]);
Creative Commons Attribution 4.0 International (CC BY 4.0) Last updated: 2025 digital image processing using scilab pdf
// Apply filter F_filtered = F_shifted .* H; F_restored = ifftshift(F_filtered); filtered_img = abs(ifft2(F_restored)); imshow(uint8(filtered_img)); // Full image processing pipeline function processed = process_image(path) // 1. Read img = imread(path); // 2. Convert to grayscale if size(img, 3) == 3 img = rgb2gray(img); end
// Erosion eroded = imerode(binary, se); // Low-pass filter in frequency domain [m, n]
// Closing (dilation followed by erosion) closed = imclose(binary, se); 8.1 Simple Thresholding // Global threshold threshold = 120; segmented = gray_img > threshold; imshow(segmented); 8.2 Otsu’s Thresholding // Compute Otsu threshold automatically [level, intensity] = otsu_thresh(gray_img); bw_otsu = gray_img > level; 8.3 Connected Components Labeling [labeled_img, num_objects] = bwlabel(bw_otsu); disp("Number of objects detected: " + string(num_objects)); 9. Fourier Transform for Frequency Domain Processing // Compute FFT F = fft2(double(gray_img)); F_shifted = fftshift(F); // Magnitude spectrum magnitude = log(abs(F_shifted) + 1); imshow(magnitude, []);
// Threshold to create binary image binary = gray_img > 128; // Structuring element (disk of radius 3) se = [0 1 0; 1 1 1; 0 1 0]; Convert to grayscale if size(img, 3) == 3
// 6. Threshold processed = edges > 50; imshow(processed); end
// 4. Enhance contrast img = histeq(img);