MATLAB: What is Pixels and what is gray level value ? and how to calculate all distances between them

presentation

7 by 7 matrix with entries 1 to 49.Each value is gray level of a pixel.
find the following distance between pixels with gray level 25 and 36.
  1. uclidean Distance
  2. City Block Distance
  3. Chessboard Distance

Best Answer

A pixel is an element of a matrix that represents something (like reflectance) of a certain scene. The gray level is the numerical valuke of the pixel. To find the distances between all possible pairs of pixels having gray levels 25 and 36 you need to first get the map of where those pixels are, then pass them into pdist2(). Since it sounds tremendously like homework, I'll give you hints so you don't get into trouble turning in my code as your own:
map25 = grayImage == 25;
map36 = ..............
[rows25, columns25] = find(map25);
xy25 = [columns25(:), rows25(:)];
distances = pdist2(xy25, ......................
That's pretty much it. Just fill out the code to get stuff for the 36 case and pass in the right distance method into pdist2, which is in the Statistics and Machine Learning Toolbox.