Hi @motaz yusuf
I understand that you have some queries regarding the errors you are encountering. Let’s break them down one by one:
g = g >= T;
This line is performing a thresholding operation on the image “g”. This operation creates a logical array where each element is true if the corresponding element in “g” is greater than or equal to “T”, and false otherwise, thus resulting in a binary image.
The errors you are encountering are related to the display of the image “g” using “imshow”. The error message indicates that “g” must be a two-dimensional logical array for “imshow” to display it correctly. You can try out the following solution for resolving the error:
- If “f” is a color image, “imfilter” might return a 3D array. Convert “f” to grayscale before processing.
- Verify that “f” is read correctly and is two-dimensional if it's supposed to be a grayscale image.
Here is the slightly revised version of your code considering the above points:
f = imread('pointDetection.jpg');
% Convert to grayscale if the image is not already
if size(f, 3) == 3
f = rgb2gray(f);
end
w = [-1, -1, -1; -1, 8, -1; -1, -1, -1];
g = abs(imfilter(double(f), w));
T = max(g(:));
g = logical(g >= T);
subplot(121), imshow(f), title('Original Image');
subplot(122), imshow(g), title('Result of Point Detection');
For detailed understanding of “imshow”, “imfilter” and “subplot” refer to the following documentation:
- https://www.mathworks.com/help/releases/R2019a/matlab/ref/imshow.html
- https://www.mathworks.com/help/releases/R2019a/images/ref/imfilter.html
- https://www.mathworks.com/help/releases/R2019a/matlab/ref/subplot.html
Hope that Helps!.