How to compress a location map using JBig compression?

조회 수: 5 (최근 30일)
Aarach Sap
Aarach Sap 2016년 9월 26일
댓글: Pengfei 2023년 3월 19일
function [y,nbr_bits] = perform_jbig_coding(x)
% perform_jbig_coding - perform binary image coding
%
% [y,nbr_bits] = perform_jbig_coding(x);
%
% It requires pbmtojbg and jbgtopbm executable.
%
% Copyright (c) 2006 Gabriel Peyr
name_pbm = 'b.pbm';
name_jbg = 'c.jbg';
if size(x,1)>1 && size(x,2)>1
% forward transform
% save as pbm
imwrite(rescale(x), name_pbm, 'pbm');
% convert to jgib
!pbmtojbg tmp.pbm tmp.jbg
% read jbig file
fid = fopen(name_jbg);
if fid<0
error('Unable to open Jbig file.');
end
[y,cnt] = fread(fid, Inf);
fclose(fid);
nbr_bits = length(y)*8;
% remove tmp files
!del tmp.jbg
!del tmp.pbm
else
% backward transform
fid = fopen(name_jbg, 'wb');
if fid<0
error('Unable to open Jbig file.');
end
fwrite(fid, x);
fclose(fid);
% convert to pbm
!jbgtopbm tmp.jbg tmp.pbm
% read pbm
y = imread(name_pbm);
% remove tmp files
!del tmp.jbg
!del tmp.pbm
nbr_bits = -1;
end
Actually, I find this code in matlab. But I don't understand why two ".pbm" and ".jbg" are needed. I have only one location map(.pbm) to compress. As I am very new to programming, it is really hard to understand. Please help me.
  댓글 수: 1
Pengfei
Pengfei 2023년 3월 19일
Hello, have you implemented JBIG compression and decompression? I am currently struggling with these two issues

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2016년 9월 26일
The code does not do the JBIG compression in MATLAB. Instead it calls upon an external program to do the work. That external program happens to be able to handle PBM files and convert them to JBIG files, so the image is saved to a temporary .pbm and converted to .jbg . The file is then read in so that the result of the conversion is in memory, and the two temporary files are discarded.
The code also handles the other direction, converting binary data representing JBIG into an image. It does that by writing the binary data out as a .jbg file, and using an external program to convert the .jbg file to .pbm and then reading the .pbm .
  댓글 수: 2
Aarach Sap
Aarach Sap 2016년 9월 26일
Thank you very much for the detail. Would you please help me how I can do JBIG compression in matlab. Is there any source code to implement?
Walter Roberson
Walter Roberson 2016년 9월 26일
You can get http://www.cl.cam.ac.uk/~mgk25/jbigkit/ and use calllib() to make calls into it. It appears that this is the origin of the PBM to JBIG program.
The algorithm looks like it is not trivial, and the list of (expired) patents is surprisingly long, suggesting that it is not as simple as it sounds at first. I would not recommend implementing in MATLAB unless you are being required to by someone.

댓글을 달려면 로그인하십시오.


Manikandan VM
Manikandan VM 2017년 3월 19일
I am also looking for the usage of JBIG2 in matlab. JBIG c code is already obtained from http://www.cl.cam.ac.uk/~mgk25/jbigkit/. But how to make use of it in matlab??
Let me know Mr. Aarach Sap solved the issue or not??

Shounak Shastri
Shounak Shastri 2018년 3월 27일
Download the toolbox and paste it in your Matlab folder. Make sure it is added to your current working path.
Open the compile_mex.m file and comment lines 8-58 and 75-80. Execute the file.
Once this is dene, the function should be usable.
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 3월 27일
That appears to be about jpeg2000 rather than about jbig?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by