如何通过关联像素值缓冲像素?

时间:2014-02-10 17:32:00

标签: matlab raster

我可以使用哪些方法来缓冲像素的关联像素值?例如,左侧的图像显示光栅图像,其像素半径值范围为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 个答案:

答案 0 :(得分: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');
相关问题