find pixels value in a volume using indexing/pixel position
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hello
I have a 500X3 matrix named PixelPos where it represents pixel position in a volume x, where the first column PixelPos(:,1) has the row numbers, PixelPos(:,2) is the column number and PixelPos(:,3) is the slice number. i want to get the value for these pixels, i used a for loop to find the value for each pixel in x but it is very time consuming, is there a function in matlab that could be helpful ?
thanks Hannah
0 commentaires
Réponses (1)
Image Analyst
le 8 Juil 2014
Looping 500 times should not be time consuming. Just make sure you access the right most values (the Z values) less frequently so you don't have a lot of memory thrashing.
clc;
PixelPos = randi(9, [50,3]); % Sample data
% Get sort order based on column 3.
[~, sortOrder] = sort(PixelPos(:,3));
sortedPositions = PixelPos(sortOrder, :);
for k = 1 : length(sortedPositions)
row = sortedPositions(k, 1);
col = sortedPositions(k, 2);
slice = sortedPositions(k, 3);
value = array3d(row, columns, slice);
fprintf('For row=%d, column=%2, slice=%d, the value = %d',...
row, col, slice, value);
end
2 commentaires
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!