This MATLAB code provides a graphical user interface (GUI) for image segmentation. The code allows users to perform various image processing tasks, such as loading an image, converting it to grayscale, adding and removing noise, performing edge detection, and histogram equalization.
-
GUI Initialization: The code initializes the GUI for image segmentation. The GUI can be a singleton, allowing only one instance to run.
-
Image Selection: Users can load an image (JPEG or PNG) by pressing the "Select Image" button. The selected image is displayed in the first axes.
-
Grayscale Conversion: Pressing the "Convert to Grayscale" button converts the selected image to grayscale and displays it in the second axes. The grayscale image's histogram is shown in the seventh axes.
-
Noise Addition: Users can add different types of noise (salt & pepper, speckle, Gaussian, or Poisson) to the grayscale image by selecting the noise type from the dropdown menu and pressing the "Add Noise" button. The noisy image is displayed in the third axes, and its histogram is shown in the seventh axes.
-
Noise Removal: Users can remove noise from the noisy image using various methods (median filtering, average filtering, Gaussian filtering, or Wiener filtering). The denoised image is displayed in the fourth axes, and its histogram is shown in the seventh axes.
-
Edge Detection: Pressing the "Edge Detection" button allows users to perform edge detection on the grayscale image using different methods (Canny, Difference of Gaussians, Sobel, Roberts, or Prewitt). The edged image is displayed in the fifth axes, and its histogram is shown in the seventh axes.
-
Histogram Equalization: Pressing the "Histogram Equalization" button applies histogram equalization to the grayscale image and displays the result in the sixth axes. The equalized histogram is shown in the seventh axes.
-
Histogram Display: The seventh axes displays the histogram of the currently processed image.
The code is organized into several functions:
imageSegmentation: Initializes the GUI and sets up the necessary callbacks.imageSegmentation_OpeningFcn: Executes before the GUI becomes visible.imageSegmentation_OutputFcn: Returns output from the GUI to the command line.selectImage_Callback: Handles the button press event for image selection.convertGray_Callback: Handles the button press event for converting the image to grayscale.addNoise_Callback: Handles the button press event for adding noise to the image.removeNoise_Callback: Handles the button press event for removing noise from the image.edgeDetection_Callback: Handles the button press event for edge detection in the image.histogramEqualization_Callback: Handles the button press event for histogram equalization.
- MATLAB R2019a or later
- Image Processing Toolbox
Feel free to use and modify this code for your image segmentation needs.

