0

I want to know size of header in an image in jpeg2000 format. how can I find out this header?

I want to calculate pure size of image.jp2 in hard disk without the size of header.

I use iminfo to find some information in matlab about image, but I don't know that can I find the header size of the image from this?

Actually I compress an image with jpeg2000 and I want to calculate rate of compression without header size.

please help me.

reihan
  • 23
  • 6
  • 1
    The JPEG2k header is pretty small, I doubt it will affect your compression ratio too much. In both jpeg2k files I checked its 12+20+345=377 bytes. – jodag Aug 10 '17 at 10:12
  • can you explain me how ?thank you very much – reihan Aug 10 '17 at 10:14
  • I opened it in a hex editor and added up the chunk sizes. See [here](http://www.file-recovery.com/jp2-signature-format.htm). If you need a hex editor I like HxD. – jodag Aug 10 '17 at 10:15
  • More detailed description of jpeg2k layout [here](https://github.com/plroit/Skyreach/wiki/Introduction-to-JPEG2000-Structure-and-Layout) – jodag Aug 10 '17 at 10:17
  • can you tell me the heaer size of lena 512*512*8 compressed with jpeg2000 by compression ratio 8? Is it like that image you said befor?377 bytes – reihan Aug 10 '17 at 10:20

1 Answers1

1

J2K files have 4 compulsory top-level boxes. They are

  • JPEG 2000 signature box
  • File Type box
  • JP2 Header box
  • Contiguous Codestream box

Each box is preceded by 4 byte marker and 4 byte size value. So in MATLAB it should be something like this

fname='C:\Users\admin\Documents\MATLAB\SO\Jpeg2k\balloon.jp2';
fid = fopen(fname);
headerMark = uint8('jp2h');
matchCnt = 1;

ch = fread(fid,1,'*uint8');
matchCnt = matchCnt+isequal(headerMark(1),ch);

while matchCnt < 5 && ~feof(fid)
    ch = fread(fid,1,'*uint8');
    matchCnt = matchCnt+isequal(headerMark(matchCnt),ch);
end
if matchCnt == 5
    fseek(fid,ftell(fid)-8,'bof');
    sizeBytes = fread(fid,4,'*uint8');
    sizeVal = arrayfun(@(x,y) bitshift(x,y,32), uint32(sizeBytes), [3:-1:0]');
    sizeVal = bitor(bitor(bitor(sizeVal(1),sizeVal(2)),sizeVal(3)),sizeVal(4));
end
fclose(fid);

I don't know what is you final task (getting header size seems to be halfway) but I recommend to see the quickstart guide for JPEG2000, JPEG2000 validator (written in python) and the validator overview.

Gryphon
  • 549
  • 3
  • 14