Search code examples
matlabimage-processingmatrixpixel

Extracting every pixel value from matrix and storing it in new one in Matlab


My problem is a typical newbie problem, I guess. My matrix looks as follows:

[102 183 301]

where the first and second dimensions are rows and columns and the third is the number of images I have to process. I am supposed to write a code to extract the pixel values for every pixel in every one of those 301 images and store it into a new matrix. I managed with only one pixel, my code looks as follows:

for y=1:301;
    inVal=squeeze(Data2(y,21,153));
    if y==1
        MAT=zeros(size(Data,3),size(inVal,1));
    end
    MAT(y)=squeeze(MAT(y,:))+inVal;
end

I previously permuted the matrix to get the pixel value out of every single image, but this does not work to find all the others or at least I wasn't able. I would really appreciate some advise as I have never coded in my life.


Solution

  • If you want the vector of all values of pixels at location (x,y) over all images, respecting your initial data layer, just do the following:

    MAT = squeeze(Data(x,y,:));