[beginner] point detection

21 Ansichten (letzte 30 Tage)
motaz yusuf
motaz yusuf am 14 Dez. 2021
Beantwortet: Vidhi Agarwal am 26 Aug. 2024
Hello people!
im a new using matlab for my image processing course and trying to do a point detection algorithm using laplacian kernel
and i have a problem understanding some parts of this simple code:
1: f = imread('pointDetection.jpg');
2: w=[-1,-1,-1;-1,8,-1;-1,-1,-1];
3: g=abs(imfilter(double(f),w));
4: T=max(g(:));
5: g=g>=T;
6: subplot(121),imshow(f),title('original image');
7: subplot(122),imshow(g),title('Result of point detection');
if the sum of product of applying the mask to a pixel larger than a particular threshold then this should be the point
my questions are (1 what does line 5 do
(2 when i run this code thses errors appear:
Error using images.internal.imageDisplayValidateParams>validateCData (line 119)
If input is logical (binary), it must be two-dimensional.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 246)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in pointdetectionassignment (line 9)
subplot(122),imshow(g),title('Result of point detection');

Antworten (1)

Vidhi Agarwal
Vidhi Agarwal am 26 Aug. 2024
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:
  1. If “f” is a color image, “imfilter” might return a 3D array. Convert “f” to grayscale before processing.
  2. 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:
Hope that Helps!.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by