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