How to get matrix from plot ???

11 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
Jan
Jan on 24 Feb 2018
It is still not clear to me, what your inputs are. John BG's solution assumes, that you have an image array of the plot, e.g. as if it is imported by imread. Is this correct? Or do you have the values of CYY and CXX available and want to create the image array e.g. to write it to a PNG file?
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
John BG
John BG on 25 Feb 2018
the sentence
I have computed CXX and CYY by some croteria aftet ploting I am getting desired figure or graph
means that the points are probably on a piece of paper, or scanned file.
Mohammad has the points, on the map, paper, but want the MATLAB matrix. HEADLINE OF THE QUESTION:
How to get matrix from plot ?
Why would any one be asking for the matrix if the matrix is already available, precisely to use the MATLAB function plot?
I don't know you, but I am not aware of any plotting command, in MATLAB or for the case in any programming language, plotting that guesses data to plot When No Such Data Has Been Yet Supplied.
For the record, to me those green stars look like street lamp posts along roads, the positions have probably been marked with a marker on paper and now, obviously, further processing is needed, and MATLAB is the perfect tool, but Mohammad asks the question, because?
How to get matrix from plot ?
Ist es jetz klar?
Viele Gruße
Jan
Jan on 25 Feb 2018
Edited: Jan on 26 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)

Jan
Jan on 24 Feb 2018
  1 Comment
Mohammad Bhat
Mohammad Bhat on 25 Feb 2018
Edited: John Kelly on 26 Feb 2018
No help, I have started new question see: Link to the new question

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!