Error while using JBIG compression.

3 views (last 30 days)
Manikandan VM
Manikandan VM on 7 Mar 2017
Commented: Pengfei on 19 Mar 2023
I need to compression a binary image(matrix of size RxC) in a lossless manner. For this I hope I can use JBIG compression, and I have downloaded the toolbox from the following link.
https://in.mathworks.com/matlabcentral/fileexchange/5104-toolbox-wavelets/content/toolbox_wavelets/perform_jbig_coding.m
I added the extracted folder to Matlab path, and I tried to call the perform_jbig_coding function in the following way
[y, nbr_bits]=perform_jbig_coding(x);
please note that x I defined as a random binary matrix of size 256x256 bits.
But while using this I am getting the following error :
_ _ 'pbmtojbg' is not recognized as an internal or external command, operable program or batch file. Error using perform_jbig_coding (line 22) Unable to open Jbig file.__
Anyone can help me to resolve this error? or Anybody can share the JBIG pure matlab code for compression and decompression?
  1 Comment
Pengfei
Pengfei on 19 Mar 2023
Hello, have you implemented JBIG compression and decompression? I am currently struggling with these two issues

Sign in to comment.

Answers (1)

Alejandro Peñuelas
Alejandro Peñuelas on 24 May 2020
Hi. Probably it is too late but this answer could be useful for other Matlab users.
Specifically for this situation, inside the function that you mentioned, the code calls two external programs 'pbmtojbg.exe' and 'jbgtopbm.exe'. The header of the function says: "It requires pbmtojbg and jbgtopbm executable." that can be generated running the make fine contained in the JBIG-KIT library that can be found at: JBIG-KIT.
Instructions to generate those executables can be found at: JBIG-KIT Instructions.
I hope this information can help someone and, if you need help, you can ask anything. This process helped me to use the jbigkit library and the mentioned function in my matlab projects.
  6 Comments
sahil sharma
sahil sharma on 10 Feb 2023
clear;
clc;
I = double(imbinarize(im2gray(imread("original.jpg"))));
[y,nbr_bits] = perform_jbig_coding(I);
I am just calling the function and I am getting this error:
zsh:1: command not found: pbmtojbg
Error using perform_jbig_coding
Unable to open Jbig file.
Error in Main (line 4)
[y,nbr_bits] = perform_jbig_coding(I);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Main is the file name calling the perform_jbig_coding function.
I have saved all the function in a same folder: Main.m, perform_jbig_coding.m, jbgtopbm (as unix executable file) and pbmtojbg (as unix executable file)
After I run the program my image "original.jpb" is converting into b.pbm, however after that the error occurs. I am also pasting the perform_jbig_coding.m code:
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.');<== It is here my program is ending
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
sahil sharma
sahil sharma on 10 Feb 2023
Also if you can remember how were you able to run the program it would be very helpful.

Sign in to comment.

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!