- 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.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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);
0 Commenti
Risposte (1)
Milan Bansal
il 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);
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 Commenti
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!