- https://www.mathworks.com/help/images/ref/imfindcircles.html
- https://www.mathworks.com/help/images/ref/mat2gray.html
- https://www.mathworks.com/help/images/ref/adapthisteq.html
Find coordinate inside circular area of 2D plots.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1680206/image.jpeg)
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);
0 comentarios
Respuestas (1)
Milan Bansal
el 29 de Abr. de 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);
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!
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!