0
我有一个16位/像素的图像文件。使用Matlab,我想生成另一个数组,其中每个元素只包含位2-10。我可以做一个for循环,但它太慢了:Bitshift在Matlab中没有循环的数组中的每个元素
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
您是否按照您发布的方式尝试了它? 'bitshift'和相关的函数都可以接受多维输入。 – Suever
是的,错误是“下标分配维度不匹配”。 – user7236719
您是否在尝试设置'image1 = image'之前确保'image1'的尺寸合适? – Suever