Digital Image Processing Using Scilab - Pdf
// 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, []);
// Compute histogram hist = imhist(gray_img); plot(hist); // Apply histogram equalization eq_img = histeq(gray_img); imshow(eq_img); min_val = min(gray_img); max_val = max(gray_img); stretched = (gray_img - min_val) / (max_val - min_val) * 255; 4.3 Gamma Correction gamma = 0.5; // darkens midtones corrected = 255 * (double(gray_img)/255)^gamma; 5. Filtering and Noise Reduction 5.1 Adding Noise noisy_img = imnoise(gray_img, 'gaussian', 0, 0.01); noisy_img = imnoise(gray_img, 'salt & pepper', 0.05); 5.2 Mean Filter (Low-pass) // 3x3 averaging kernel h = (1/9) * ones(3,3); filtered = imfilter(gray_img, h); 5.3 Median Filter (Non-linear) Better for salt-and-pepper noise:
// Get image dimensions (rows, cols, channels) size(img) gray_img = rgb2gray(img); imshow(gray_img); 3.3 Access and Modify Pixels // Access pixel at row 100, column 150 pixel = img(100, 150, :); // Set a region of interest to black img(50:100, 50:100, :) = 0; 4. Image Enhancement 4.1 Histogram Equalization Improves contrast by spreading intensity values. digital image processing using scilab pdf
median_filtered = medfilt2(gray_img, [3 3]); // Create Gaussian kernel (approx) gaussian_kernel = [1 2 1; 2 4 2; 1 2 1] / 16; gaussian_filtered = imfilter(gray_img, gaussian_kernel); 6. Edge Detection 6.1 Sobel Operator // Sobel kernels sobel_x = [-1 0 1; -2 0 2; -1 0 1]; sobel_y = [-1 -2 -1; 0 0 0; 1 2 1]; Gx = imfilter(double(gray_img), sobel_x); Gy = imfilter(double(gray_img), sobel_y);
// Write image to disk imwrite(img, 'output.png'); // Closing (dilation followed by erosion) closed =
// Dilation dilated = imdilate(binary, se);
// 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]; Image Enhancement 4
Creative Commons Attribution 4.0 International (CC BY 4.0) Last updated: 2025
Article ID: DIP-SCILAB-01 Target Audience: Engineering students, researchers, hobbyists Software Required: Scilab 6.1+ with SIVP (Scilab Image and Video Processing) toolbox 1. Introduction Digital Image Processing (DIP) involves manipulating digital images using computer algorithms. While MATLAB is the industry standard, Scilab —a free, open-source alternative—provides powerful capabilities for DIP through its SIVP (Scilab Image and Video Processing) toolbox and core functions.
// 3. Denoise with median filter img = medfilt2(img, [3 3]);
// Opening (erosion followed by dilation) opened = imopen(binary, se);