Find coordinate inside circular area of 2D plots.

3 views (last 30 days)
Hi, now I am tryting to find coordinate inside circular area of my data.
I tried to use imfindcircles in my image process toolbox. However, it did not detect my circles.
Anyone have better suggestions to get coordinate inside of holes?
clear all;
fileID=fopen('50_topo.txt','r');
formatSpec = '%f';
A=fscanf(fileID,formatSpec);
sq=zeros(256, 256);
sq=A;
sq=reshape(sq,256,[]);
%colormap(copper);
image(sq,'CDataMapping','scaled');
colorbar;
caxis([-2 2]*10^-9);
fclose(fileID);

Answers (1)

Milan Bansal
Milan Bansal on 29 Apr 2024
Hi Youngki
As per my understanding, you are trying to draw circles around the patches using imfindcircles in your image (which you created using the attached text file) but are facing issues with it. You also wish to get the coordinates of the center of those circles.
Assuming the patches are actually the blue-colored spots as shown in the image, circles around those patches can be drawn by following the steps given below:
1.) Get the matrix from the text file in the required format (as already done in your code).
clear all;
fileID=fopen('50_topo.txt','r');
formatSpec = '%f';
A=fscanf(fileID,formatSpec);
sq=zeros(256, 256);
sq=A;
sq=reshape(sq,256,[]);
2.) Since values in the matrix are very small, first normalize the "sq" to span a full range of grayscale values using mat2gray, and then apply adaptive histogram equalization using adapthisteq to improve the contrast. This will improve the visibility of the patches.
% Normalize to [0, 1]
sq_normalized = mat2gray(sq);
% Enhance contrast using histogram equalization
sq_contrast = adapthisteq(sq_normalized);
3.) Use imfindcircles to find the circles. Adjust the 'Sensitivity' and 'EdgeThreshold' parameters to accurately detect the patches. Since the patches are dark, set 'ObjectPolarity' to 'dark'.
[centers, radii, metric] = imfindcircles(sq_contrast, [5 11], 'ObjectPolarity', 'dark', 'Sensitivity', 0.96, 'EdgeThreshold', 0.15);
Warning: You just called IMFINDCIRCLES with very small radius value(s). Algorithm accuracy is limited for radius values less than or equal to 5.
4.) Plot the image and display the detected circles.
% plot the image
image(sq,'CDataMapping','scaled');
colorbar;
caxis([-2 2]*10^-9);
fclose(fileID);
% Display the detected circles
viscircles(centers, radii,'EdgeColor','r');
The coordinates of the center of the detected circles is stored in the "centers" variable.
Please refer to the following documentation links to learn more about imfindcircles, mat2gray and adapthisteq functions.
Hope this helps!

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!