Now that you have learned two different ways to work with image pixels, we will present another useful and common tool found in image processing software, which is thresholding. Image thresholding can be defined as the process of creating binary images by setting pixels with values above a certain threshold to 1 and the rest to 0. It is usually used for separating the foreground from the background of an image. As we did for the previous examples, we will show three different ways to implement image thresholding in MATLAB; using for
loops, a special way of indexing, and using a ready-made thresholding MATLAB function.
The classic programming way to implement grayscale image thresholding is by using two nested for
loops in a similar fashion to the one used in the previous sections. More specifically, the following script can be used to threshold my_image.bmp
:
img = imread('my_image.bmp'); % Read image subplot (1,2,1) % Open a figure for...