我有一个16位/像素的图像文件。使用Matlab,我想生成另一个数组,其中每个元素只包含2-10位。我可以在for循环中完成,但它太慢了:
if mod(j,2) ~= 0
image1(i,j) = bitshift(image(i,j),-2); % shift the LL bits to the left
else
tmp = bitand(image(i,j),3); % save off the lower 2 bits 00000011
adder = bitshift(tmp,6); % shift to new positions in LL
image1(i,j) = bitshift(image(i,j),-2); % shift the UL bits to the right
image1(i,j-1) = bitor(image1(i,j-1),adder); add in the bits from the UL
end有没有办法做下面这样的事情呢?
image1(:,1:2:end) = bitshift(image(:,1:2:end),-2);
etc发布于 2016-12-02 02:16:00
bitand和bitor都将多维数组作为第一个输入进行操作。您看到的问题可能是因为您已将image1初始化为与image不同的大小,因此使用以下命令会出现尺寸不匹配错误
image1(:,1:2:end) = bitshift(image(:,1:2:end),-2); 要解决此问题,请在调用上述命令之前将image1初始化为image或image大小的零数组
image1 = zeros(size(image));
image1(:,1:2:end) = bitshift(image(:,1:2:end),-2); https://stackoverflow.com/questions/40913440
复制相似问题