# Vectorization, check if points coordinate is exist in an image or no

2 visualizzazioni (ultimi 30 giorni)
Mahsa il 9 Ott 2017
Commentato: Mahsa il 12 Ott 2017
Can anyone help me to vectorize this for loop. It is basically ckecking if the x and y coordinate of is one in N matrix or not. Thank you
for i = 1:length(coordinates)
DD = coordinates(i,:);
DDD = N(DD(1),DD(2));
if DDD ==1
%%%if the dicom point is inside the mask
signVector(i) = -1;
else
%%%if the dicom point is outside the mask
signVector(i) = +1;
end
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Teja Muppirala il 10 Ott 2017
signVector = ones(size(coordinates,1),1);
inds = sub2ind(size(N),coordinates(:,1),coordinates(:,2)); % Convert to linear indices
signVector( N(inds)==1 ) = -1;
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Mahsa il 12 Ott 2017
Thank you. I was not aware of sub2ind function.

Accedi per commentare.

### Più risposte (2)

Andrei Bobrov il 9 Ott 2017
Modificato: Andrei Bobrov il 9 Ott 2017
ii = coordinates;
d3 = N(ii(:,1),ii(:,2));
signVector = -ones(numel(d3),1);
signVector(d3 ~= 1) = 1;
##### 2 CommentiMostra NessunoNascondi Nessuno
Mahsa il 9 Ott 2017
Thank you. but it did not work d3 should be a vector not a matrix
Image Analyst il 10 Ott 2017
Give us code, or a .mat file, to generate coordinates so we can see what you're seeing.

Accedi per commentare.

Image Analyst il 9 Ott 2017
Be careful. If coordinates is an array of (x,y) and N is an array, then you'll need to check N(y, x), not N(x,y) as you have perhaps done. Remember (row, column) is (y, x) NOT (x,y).
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Mahsa il 10 Ott 2017
It is true. Thanks

Accedi per commentare.

### Categorie

Scopri di più su Geometric Transformation and Image Registration 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!

Translated by