dictionary - Building a map from a matrix in Matlab -


I have a matrix which holds the integer in a bound range (0..255) and I have a value of table mapping (0. 255) All the coordinates in the matrix which hold this value.

What is the best way to achieve this? - I thought about using containers. Map for work but does not support multiple values ​​in the map per key. I could use lists but it would be ineligible because I had to create a new list at every frequency.

"post-text" itemprop = "text">

A vector solution, which gives the same output, is to sort all the pixel values ​​in your image using the function, the function Convert linear indexes by returning to the subscribed index using, and aggregate them together in a single cell array and:

  A = rand ([0 255], [5 5] 'UIT8'); % # A sample matrix [value, index] = sort (double (A (:)); Sort all pixel values ​​[or, x] = ind 2 sub (size (a), index); Convert% # clerical index to subscript numbers = submit (value + 1,1, [256 1]); % # Number of maps of each value map = mat2cell ([y x], counting); Create a # 256-by-1 cell array  

Now, for a given integer value iValue you get N In the matrix of 2 - y (first column) and x (second column) coordinates for the N pixels in the picture with that value Do the following:

  key = double (iValue) +1; #% To avoid integer saturation points = map {key}; In addition, if you are interested, then you have a composition array with the  map  field  x Using  and  y  function: 

  map = straight ('x', matellelcel (x, calculation), 'y', matodec , It matters));  

and you later direct to x and y with a value iValue for pixels Can:

key = double (iValue) +1; X = map (key) .x; Y = map (key). Y

Comments