3D matrix mapping and manipulation

3 views (last 30 days)
I have a 768x320x361 matrix which is my image(Which is a Hyper-Spectral image). How would I call or get a specific pixel value such as 113:341:361. The goal of this is to take the values of 30 different "Select" pixels and repopulate them randomly into a 30x30x361 matrix. Any guidance on this will be appreciated, thanks.
  1 Comment
Geoff Hayes
Geoff Hayes on 2 Sep 2014
Shane - if img is your 768x320x361 matrix/image, then to get a specific pixel value, just do
pixVal = img(113,341,361);

Sign in to comment.

Accepted Answer

Gitesh Nandre
Gitesh Nandre on 2 Sep 2014
As Geoff has correctly suggested, you can get a specific pixel value for a specific index such as 113:314:361 as follows:
pixVal = img(113,314,361) %where 'img' is your image matrix of the dimension 768x320x361.
In order to perform the next task, i.e. to randomly distribute 30 such specific pixel values in 30x30x361 matrix say 'mat', you can do following steps:
%First get all 30 values which you want to randomly distribute and put them into an array of dimention 1 x 30
%For demonstration purposes, I am generating random 30 values.
values = rand(1,30);
%Now generate the random 30 linear indices for the destination matrix 'mat' and put them into the array 'randIndices'.
randIndices = randi(30*30*361,1,30);
%Now , just assign the values to the locations pointed by these indices in matrix 'mat'
mat(randIndices) = values;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!