Encoding the image using Huffman transform and converting to non-overlapping blocks

4 次查看(过去 30 天)
Hi, I encoded an image with huffman transform and converted the image into a contiguous bit string. I want to convert this bit string into 4x4 blocks. Can anyone guide me?

回答(1 个)

Meet
Meet 2024-9-12
Hi Javad,
To convert your Huffman-encoded image bit string into 4x4 blocks you could follow these steps:
  1. Ensure that the length of your bit string is a multiple of 16. If it is not, pad it with zeros.
  2. Divide this bit string into segments of 16 bits each. Each segment will correspond to one 4x4 block.
  3. Convert each 16-bit segment into a 4x4 block. This can be done by reshaping the segment into a 4x4 matrix using “reshape” function.
Following is a sample code for the same:
% Sample bit string of encoded image after huffman transform.
bitString = '110101011001011011110000100110101010101010101010';
bitStringLength = length(bitString);
% Calculate the number of 4x4 blocks.
numBlocks = bitStringLength / 16;
% Cell array to store final result.
blocks = cell(numBlocks, 1);
% Divide the bit string into 4x4 blocks.
for i = 1:numBlocks
% Extract 16-bit data from the bit string.
bitSegment = bitString((i-1)*16 + 1:i*16);
% Convert the 16-bit data into a 4x4 block
block = reshape(bitSegment, [4, 4])';
blocks{i} = block;
end
% Display the blocks
for i = 1:numBlocks
fprintf('Block %d:\n', i);
disp(blocks{i});
end
You can refer to the resource below for more information:
  1 个评论
Walter Roberson
Walter Roberson 2024-9-12
bitString = '110101011001011011110000100110101010101010101010';
After all padding has been done, you can use
num2cell(reshape(bitString, 4, 4, []), [1 2])
ans = 1x1x3 cell array
ans(:,:,1) = {4x4 char} ans(:,:,2) = {4x4 char} ans(:,:,3) = {4x4 char}

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by