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

4 vues (au cours des 30 derniers jours)
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?

Réponses (1)

Meet
Meet le 12 Sep 2024
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 commentaire
Walter Roberson
Walter Roberson le 12 Sep 2024
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}

Connectez-vous pour commenter.

Catégories

En savoir plus sur Denoising and Compression dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by