2014-02-10 27 views
0

我可以使用什麼方法來緩衝像素的相關像素值?例如,左側的圖像顯示的像素半徑值範圍爲0 - 5(注意「黑色」值爲0)的光柵圖像。右側的圖像顯示了我試圖根據這些像素值生成的緩衝區。每個堆棧交換策略,我還包括一個可重現數據的MATLAB腳本。如何緩衝像素的關聯像素值?

enter image description here


% Generate a grid of 0s to begin with. 
m = zeros(300, 400, 'uint8'); 

% Generate 1000 random pixels. 
numRandom = 1000; 
linearIndices = randi(numel(m), 1, numRandom); 

% Assign a radius value of 1-5 for each pixel 
m(linearIndices) = randi(5, [numel(linearIndices) 1]); 

% Display it. 
image(m); 
colormap(hot); 
+1

編輯:NVM,使用這裏所說的緩衝區是不明確的。 –

+0

@Ashish您在提供的解決方案中使用「緩衝區」是正確的。 – Borealis

回答

1

一種方法:

% Generate a grid of 0's to begin with. 
m = zeros(300, 400, 'uint8'); 

% Generate 1000 random pixels. 
numRandom = 9; 
linearIndices = randi(numel(m), 1, numRandom); 

% Assign a radius value of 1-5 for each pixel 
m(linearIndices) = randi(5, [numel(linearIndices) 1]); 



%% 
buffer = false(size(m)); 
for radius =1:5 % update to actual range 
    im_r = m==radius; 
    se = strel('disk',radius); 
    im_rb = imfilter(im_r, double(se.getnhood())); 

    buffer = buffer | im_rb; 
end 

imshowpair(m,buffer,'montage'); 
+0

非常感謝@Ashish。這是一個創造性的簡單解決方案。 – Borealis