find pixels value in a volume using indexing/pixel position
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 8 Jul 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
See Also
Categories
Find more on Image Processing Toolbox 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!