Clear Filters
Clear Filters

Why do image coordinate switches when using getpts function?

2 views (last 30 days)
I have a 96x256x256 data, and I try to pick a pixel from the 256x256 to get data. When I use the getpts function, I get different x and y coordinates. Here is my approach to my data: 1. I have data that contain x and y coordinates, and data set(size of 96) at x-y coordinate. 2. I re-edited the data so I can put it into a matrix called tissue_map by doing a for loop:
for i = 1:length(xcoord)
tissue_map(:,xcoord(i),ycoord(i)) = tissueData(:,i);
end
After this, I use getpts to get a coordinate on one slice of the matrix, say tissue_map(1,120,130):
fig = imagesc(tissue_map(1,:,:));
[x, y] = getpts(fig);
where I get:
x = 130
y = 120
What is it that I'm doing wrong? I couldn't figure out why.

Answers (1)

Walter Roberson
Walter Roberson on 1 Dec 2017
I do not see a problem?
In matrix indexing, "up/down" is row indexing, the first index. Up/down corresponds to Y coordinates. So x = 130, y = 120 is row 120 column 130, index (120,130)
  3 Comments
Arbol
Arbol on 2 Dec 2017
1. I have raw data that give x and y coordinate with size of 1x(256*256). Where each row of x increases by 1, each column of y increases by 1. I noticed that this is opposite than MATLAB's indexing. So:
2. I do some data processing to get my region of interest (xvec and yvec) to then put it in:
fit_xcoord = zeros(256,256);
fit_ycoord = zeros(256,256);
fit_intensity = zeros(length(time),256,256);
for i=1:length(xvec)
IPx = xvec(i); IPy = yvec(i);
fit_zcoord = zcoord;
%-- Flip x and y coordinates
fit_xcoord(IPx,IPy)= ycoord(IPx,IPy);
fit_ycoord(IPx,IPy)= xcoord(IPx,IPy);
fit_intensity(:,IPx,IPy) = intensity_subtracted(:,IPx,IPy);
end
Where I flipped the xvec and yvec in the fit_xcoord and fit_ycoord so the indexing are similar to MATLAB's.
3. I use what I asked above to get my coordinate of interest by using getpts:
for i = 1:length(xcoord)
tissue_map(:,xcoord(i),ycoord(i)) = tissueData(:,i);
end
fig = imagesc(tissue_map(1,:,:));
[x, y] = getpts(fig);
where I get:
x = 130
y = 120
Where xcoord = fit_xcoord and ycoord = fit_ycoord from step 2.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!