Plotting the coordinates of maxima

2 views (last 30 days)
Sk
Sk on 6 Jan 2020
Commented: Sk on 8 Jan 2020
I want to get all the coordinates of the area where maxima is detected i.e. the blob detected area as a separate binary image.The maxima coordinates should be white and other pixels must be black. So im creating an array 'a' in the size of 1655x1655. While execution, in the output image the points are not spreaded entirely for 1655x1655. They are seen only on left top corner of the entire zero array. Im not sure whether all the values of maxima are getting plotted or is there some other issue. How to solve this issue? Pls help me with this. The code and input image is provided in the attached file.
Output image:
output.jpg
  4 Comments
Guillaume
Guillaume on 6 Jan 2020
Missing from your code is any comment explaining what it attempts to do. In particular, what is the puprose of each loop?
Note that:
k=1.28;
sigma=2;
logScales=zeros(1,15);
for i=1 : 15
logScales(1,i)= sigma;
sigma=k*sigma;
end
is simply:
k = 1.28;
sigma = 2;
logScales = sigma * k.^(0:14);
Sk
Sk on 7 Jan 2020
Edited: Guillaume on 7 Jan 2020
% Implementation of Laplacian Blob detector
clc;
close all;
clear all;
img=imread('F:\matlab\LCA\rgb.jpg');
img=rgb2gray(img);
I=img;
[h,w]= size(img);
n=1;
scale_space = zeros(h,w,n);
k=1.28;
sigma=2;
logScales=zeros(1,15);
% Calculating sigma for different scale space by multiplying sigma with k
for i=1 : 15
logScales(1,i)= sigma;
sigma=k*sigma;
end
% Creating filter and applying it on image and creating scale space
for scale = logScales
filter = fspecial('log', 2*ceil(scale*3)+1, scale);
filter=(scale.^2)*filter; %Scale Normalize Laplacian
imgnew=imfilter(img,filter,'replicate');
imgnew=imgnew.*imgnew; %Square of Laplacian Response
if n==1
scale_space=imgnew;
else
scale_space=cat(3,scale_space,imgnew);
end
n=n+1;
end
% Performing Non Maximum Supression on each 2D layer of the Scale Space
for i=1:15
cim = scale_space(:,:,i);
mx = ordfilt2(cim,9,ones(3,3)) ; %Getting the maximas for the layer
if i==1
mx_new=mx;
else
mx_new=cat(3,mx_new,mx);
end
end
% Finding Maximum values in the 3D Scale Space
nms_3d=max(mx_new,[],3);
nms_3d= (nms_3d==mx_new).*mx_new;
% Replacing all non maximum values with zeros (for every 2D scale space
% slice). Finding coordinates of the maximas and drawing circles for that
% maxima.
for i=1: 15
radius=1.414 * logScales(i);
thresh=.009;
cim = scale_space(:,:,i);
cim = ((cim==nms_3d(:,:,i))&(cim>thresh));
[r,c] = find(cim);
if i==1
r1=r;
c1=c;
rad=radius;
rad=repmat(radius,size(r,1),1);
else
rad2=repmat(radius,size(r,1),1);
rad=cat(1,rad,rad2);
r1=cat(1,r1,r);
c1=cat(1,c1,c);
end
end
end
% Get the maxima coordinates in white pixels in a separate array
[j,k]=size(r1);
[p,s]=size(c1);
a=zeros([p,j]);
for i=1:size(c1)
a(c1(i),r1(i))=1;
end
figure
imshow(a);

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 6 Jan 2020
Try imregionalmax() and find():
maxImage = imregionalmax(binaryImage);
[rows, columns] = find(maxImage);
  5 Comments
Image Analyst
Image Analyst on 7 Jan 2020
You have not defined what maxima is. imregionalmax() will give a 1 where a pixel is the highest value in a local window. For your RGB image of characters in rock, it's not clear that the characters are the brightest pixels.
As far as segmenting the characters carved in rock, I think there are probably papers on that. Check here VisionBib
Sk
Sk on 8 Jan 2020
Thank you. I will check those papers.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!