Getting a thin vertical line as output image.
1 次查看(过去 30 天)
显示 更早的评论
I have applied Huffman encoding to compress an image but the output image is a thin vertical line. I guess it is because it is still in vector form. So my question is about how to convert it to the desired form.
0 个评论
采纳的回答
Image Analyst
2018-10-14
Uncompress, then display it.
7 个评论
Image Analyst
2018-10-14
You can display the compressed data as an image regardless of how you did it, though as Walter says, it is not really an image even though you're displaying it as an image. To see the image, you'd have to reconstruct the image and then it will look exactly, or roughly, like the original image depending on how much compression was done.
For example let's say that I had a square 10x10 image (100 pixels) of pixels all with the value 137. I could compress this into only two numbers [100, 137]. I could then show two pixels with a value of 100 and a value of 137, but of course this two pixel image doesn't look anything like the original 10x10 2-D image since it's just two values, not 100 values.
Walter Roberson
2018-10-14
Suppose I had
Carol Alice Alice Carol Bob Bob Ted Alice Ted Alice Bob Alice Ted Bob Ted Carol Ted Ted Alice Carol
then I could compress that to symbols = {'Bob', 'Ted', 'Carol', 'Alice'} together with idx = [3 4 4 3 1 1 2 4 2 4 1 4 2 1 2 3 2 2 4 3] where idx is the index into the symbols array. In turn idx has only four possible states (in this example) and could be written into binary as 1011111000000111011100110100011001011110 where each 2 digits together encodes an idx value, 00 -> 1, 01 -> 2, 10 -> 3, 11 -> 4
So in this example we have now encoded Carol Alice Alice Carol Bob Bob Ted Alice Ted Alice Bob Alice Ted Bob Ted Carol Ted Ted Alice Carol as {'Bob', 'Ted', 'Carol', 'Alice'} (the dictionary) and 1011111000000111011100110100011001011110 (binary).
And you are doing the equivalent of asking to see the the stream of characters associated with the binary, because the original were characters.
Well, it is possible to do that:
char(bin2dec(reshape(dec2base(idx-1,2).',8,[]).').')
ans =
'¾sF^'
where the character between the 3/4 and the s is the ASCII BELL character... but is this even slightly meaningful as an displayed output?
The huffman encoding of your image is similar to the above case, except worse in the sense that the encoding for the different symbols is different lengths, so if you happened to see the same character on output (such as 's') then you could not assume that it was encoding the same input: it could have been caused in multiple ways since the boundary between symbols can be inside the middle of a character (when you define a character as being 8 bit.)
The huffman encoding is not an image itself: it is just data similar to 1011111000000111011100110100011001011110 -- and in fact the same data might encode quite different images, depending on the dictionary that was being used.
For lossy image compression formats, it can make sense to reconstruct the image from the compressed data and then to compare the original image to the degraded image.
For a lossless image compression format, you could reconstruct the image from the compressed data and then compare to the original image for the purpose of proving that the compression / reconstruction routines are working.
But in both cases, lossy and lossless, the compressed data is not an image itself, and would look like noise when viewed. Indeed, if you can see structure in the compressed data, then that indicates that there was probably room for a better compression routine.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Import, Export, and Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!