MATLAB Answers

How to get matrix from plot ???

27 views (last 30 days)
Mohammad Bhat
Mohammad Bhat on 23 Feb 2018
Edited: Jan on 26 Feb 2018
Hi,I plotted a CYY and CXX having certain values .....
plot(CYY,CXX,'g*');
Now I want to get those plotted values marked '*' in plot in an matrix, can it be done???
  2 Comments
Mohammad Bhat
Mohammad Bhat on 24 Feb 2018
I have CXX and CYY....

Sign in to comment.

Accepted Answer

John BG
John BG on 23 Feb 2018
Hi Mohammad
1.
Allow me to start with the same image you have supplied op.jpg
close all;clc;clear all
input_image='001.jpg';
A=imread(input_image);
figure(1);imshow(A);
.
.
Attached both start image and script to help reproduce result.
.
2. Amplify the image to avoid some too close stars overlapping and then alias would happen
.
Ar=imresize(A,20);
.
3. Green minus Blue shows a good response to blur a bit the starts yet keeping sharpness of each peak
.
A21=Ar(:,:,2)-Ar(:,:,3); % green - blue
figure(2);h1=imshow(A21);
.
.
4. Comment, at this point imcontrast can be used to show what range of pixel values are most useful
.
imcontrast(h1); % thresholds 59 and 123
.
.
instead one can manually perform the same pixel selection without imcontrast
th1=100;th2=59;
A21(A21<th2)=0;
A21(A21>=th1)=255;
figure(3);imshow(A21);
.
.
5. Reducing the size of the image a bit to save time i next step finding 2D peaks
.
A2=imresize(A21,.1);
figure(4);imshow(A2);
6.
Use Natan's function FastPeakFind.m available here:
.
pk3=FastPeakFind(A2);
figure(5);imagesc(A2); hold on
figure(5);plot(pk3(1:2:end),pk3(2:2:end),'r+')
.
.
7.
FastPeakFind returns a single file list of coordinates that are the [x y] coordinates interleaved, to obtain the paired coordinates:
x_peak=pk3(1:2:end);
y_peak=pk3(2:2:end);
p_stars=[x_peak y_peak];
8.
The amount of stars found is:
size(p_stars,1)
ans =
152
Mohammad
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG
A couple additional comments:
9.1. tried *imfindcircles* but all tested parameters did not return any result as close as the previous steps.
[centers, radii, metric] = imfindcircles(A21,[8 15],'ObjectPolarity','bright','Sensitivity',.94);
[centers, radii, metric] = imfindcircles(A21,[15 31],'Method','PhaseCode','ObjectPolarity','bright','Sensitivity',.94);
radii=floor(radii);
viscircles(centers, radii,'EdgeColor','r');
9.2. tried *findpeaks2.m* available from here:
% https://www.mathworks.com/matlabcentral/fileexchange/46806-findpeaks2-m?s_tid=srchtitle
% [pk2,id2]=findpeaks2(A2);
2 minutes waiting and still busy.
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centers, radii,'EdgeColor','r');
  14 Comments
Jan
Jan on 25 Feb 2018
@John BG: See Mohammad's refined question, where he explains again, that he has the CXX and CYY coordinates, and whats the adjacency matrix: https://www.mathworks.com/matlabcentral/answers/384657-how-to-form-adjacency-matrix-from-cxx-and-cyy-where-cxx-and-cyy-contains-collectively-some-informati#comment_539237.
Your answer shows how to digitize the plot, but this does not help in any way to get the adjacency matrix for the available coordinates.

Sign in to comment.

More Answers (1)

Community Treasure Hunt

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

Start Hunting!