Matlab 如何通过相关像素值缓冲像素?
我可以使用什么方法通过相关像素值缓冲像素?例如,左侧的图像显示像素半径值范围为0-5(注意“黑色”值为0)的光栅图像。右边的图像显示了我试图基于这些像素值生成的缓冲区。每个堆栈交换策略,我还包括一个用于可复制数据的MATLAB脚本Matlab 如何通过相关像素值缓冲像素?,matlab,raster,Matlab,Raster,我可以使用什么方法通过相关像素值缓冲像素?例如,左侧的图像显示像素半径值范围为0-5(注意“黑色”值为0)的光栅图像。右边的图像显示了我试图基于这些像素值生成的缓冲区。每个堆栈交换策略,我还包括一个用于可复制数据的MATLAB脚本 一种方法: % Generate a grid of 0's to begin with. m = zeros(300, 400, 'uint8'); % Generate 1000 random pixels. numRandom = 9; linearInd
一种方法:
% 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');
编辑:nvm,这里的“缓冲区”一词的用法不清楚。@Ashish您在提供的解决方案中使用的“缓冲区”是正确的。非常感谢@Ashish。这是一个创造性的简单解决方案。
% 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');