2017-07-03 96 views
1

我有劇情圖像:MATLAB

  1. 的圖像,保存爲像素的陣列。
  2. 單元格數組的單元格數與圖像中的像素數相同。

基本上,單元陣列的每個單元對應於圖像中的像素的位置。

我想在三維圖的xy平面上繪製圖像,然後將這些值繪製在z平面的單元陣列中。每個單元格中的值對應於圖像的像素位置和相應的z值。

例如,

cellarray{1} = [10 2056] 
cellarray{2} = [18 1928] 

在XY平面內顯示的圖像,那麼我想

  • 甲點上方的圖像的像素1作圖,與z值的2056
  • 的點繪製上述圖像的像素18,與1928年

一個z值我也行使用imagesc(image)來繪製圖像,但我不知道如何轉換單元格數組中的日期以創建3D圖,其中z值高於圖像的相應像素。

+0

是在cellarray {N}唯一的第一要素? – Wolfie

+0

是的,它們是獨一無二的。 cellarray {1}的所有第一個元素都是1,cellarray {2}的所有第一個元素都是2,等等。感謝您的幫助! – Anonymous

+0

但是你在上面說過,例如'cellarray {2} = [18 1928]'所以第一個元素是18,而不是2? – Wolfie

回答

0

假設您有一些單元陣列cellarray,其中包含16個[pixel number, z value]對。這兩行成立了一個隨機演示...

% Set up random cell array, with 1x2 arrays in each cell 
% First number in each array is unique pixel number, second is z value 
z = num2cell(randi(64,4,4)); 
cellarray = cell(4,4); for ii = 1:16; cellarray{ii} = [ii z{ii}]; end; 

現在,我們想繪製這一點,所以它轉換成16×2矩陣,其中每行是1x2的細胞之一:

% Use the colon (:) to make cell array one column, use cell2mat to convert to matrix 
g = cell2mat(cellarray(:)); 

要從索引獲取2D x和y座標,可以使用ind2sub

[x, y] = ind2sub([4, 4], g(:,1)); % Change [4, 4] to the size of your image 

現在你可以使用plot3繪製這些,持有,如果要保留以前的情節(如圖像):

hold on % to retain previous plot, like from imagesc 
plot3(x, y, g(:,2), '.'); % Using the dot to specify points not a line 
+0

非常感謝!這真的很有幫助和真棒。我想知道你認爲哪個函數最適合在3d圖的xy平面中繪製圖像本身。 imagesc()返回一個二維圖,所以我一直在使用這一點的代碼: – Anonymous

+0

沒問題,很高興我可以幫助 – Wolfie