Skip to main content

Bilevel Troubles

12 replies [Last post]
dbuddeii
Offline
Joined: 2008-08-29
Points: 0

I have been look for a way to read in a TIFF image and determine if it is a bilevel (black and white) image. So far from reading the forums and searching on google I have not been able to find anything. I have no idea where to even begin at this point.

Any suggestions on how to accomplish this will be most appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marcojacob
Offline
Joined: 2006-07-10
Points: 0

You have to consult the ImageIO API at http://java.sun.com/j2se/1.4.2/docs/api/
(javax.media.imageio) to get an overview about how to read image (metadata) with
ImageIO.

A short intro to reading and processing metadata:

1. ImageIO.createImageInputStream(Object, boolean)
2. ImageIO.getReaderByMime (String) - you can take the first reader
3. imageReader.setInput(Object anImageInputStream)
4. imageReader.getImageMetadata(int imageIndex, String formatName, Set nodeNames)
e.g. to read only the XML node "Data" of the image neutral image metadata
imageReader.getImageMetadata(0, "javax_imageio_1.0", new Set(1).add("Data"))
5. Process with the IIOMetadata object as desired, consult the API

You can get an overview of the image neutral metadata format at

http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/metadata/doc-files...

You can check the compression which can be bilevel compression only.
Also you can check the node at path "javax_imageio_1.0/Data/BitsPerSample".
You will get an array of Integers. For bilevel images this will hold only one Integer
with value 2 (2 Bit one sample). RGB JPEG will have 3 Integer with value 8
(8 Bit three samples --> 24 bit color).

Kind regards,
Marco

[changed "Chroma" to "Data"]

Message was edited by: marcojacob

marcojacob
Offline
Joined: 2006-07-10
Points: 0

Sorry for posting again, but be aware giving "javax_imageio_1.0" and "Chroma"
(should be "Data" in this case) in the Set will return only image neutral metadata
only containing the nodes given in the set. Giving "Chroma" you will never be able
to get "Data" content.

dbuddeii
Offline
Joined: 2008-08-29
Points: 0

Thank you both for your answers. This gives me a good start in the right direction.

The top of the thread says 'Use the "helpful" or "correct" buttons to award points to replies.' I don't know if this forumn does have the ability of awarding points, but if it is important to you two, please let me know how to do it, because I don't see a 'helpful' or 'correct' button to use.

Message was edited by: dbuddeii

Fabrizio Giudici

Hello.

I'm having a problem with a JPEG file that contains a thumnail, but it
is not detected by ImageIO.
The file is

https://imaging.dev.java.net/svn/imaging/trunk/www/TestSets/kijiro/Sony/...

The test code for reproducing the problem is:

final File file = new File("kijiro/Sony/A100/JPG/DSC00041.JPG");
final Iterator i =
ImageIO.getImageReadersByFormatName("jpeg");
final ImageReader ir = i.next();
assertEquals("com.sun.imageio.plugins.jpeg.JPEGImageReader",
ir.getClass().getName());
ir.setInput(ImageIO.createImageInputStream(file));
assertEquals(1, ir.getNumThumbnails(0)); // fails

I'm also attaching the dump from exifprobe which demonstrates that there
is indeed a thumbnail. I think I can work around it by reading the
metadata, manually getting JPEGInterchangeFormat and opening the
thumbnail on my own, but I'd like to be confirmed that this is a bug.

Thanks.

File Name = DSC00041.JPG
File Type = JPEG
File Size = 2511779
@000000000=0 :
@0x0000002=2 : 0xffe1 length 53681, 'Exif'
@0x000000c=12 : TIFF(MM=0x4d4d) magic=0x002a='*\0' ifd offset
= 8 (+ 12 = 0x14/20)
@0x0000014=20 : 12 entries starting at file offset 0x16=22
@0x0000016=22 : <0x010e= 270> ImageDescription
[2 =ASCII 30] = @0xaa=170
@0x0000022=34 : <0x010f= 271> Make
[2 =ASCII 16] = @0xc8=200
@0x000002e=46 : <0x0110= 272> Model
[2 =ASCII 10] = @0xd8=216
@0x000003a=58 : <0x0112= 274> Orientation
[3 =SHORT 1] = 1 = '0,0 is top left'
@0x0000046=70 : <0x011a= 282> XResolution
[5 =RATIONAL 1] = @0xe2=226
@0x0000052=82 : <0x011b= 283> YResolution
[5 =RATIONAL 1] = @0xea=234
@0x000005e=94 : <0x0128= 296> ResolutionUnit
[3 =SHORT 1] = 2 = 'pixels per inch'
@0x000006a=106 : <0x0131= 305> Software
[2 =ASCII 16] = @0xf2=242
@0x0000076=118 : <0x0132= 306> DateTime
[2 =ASCII 20] = @0x102=258
@0x0000082=130 : <0x0213= 531> YCbCrPositioning
[3 =SHORT 1] = 1 = 'centered'
@0x000008e=142 : <0x8769=34665> ExifIFDPointer
[4 =LONG 1] = @0x192=402
@0x000009a=154 : <0xc4a5=50341> PrintIM
[7 =UNDEFINED 124] = @0x116=278
@0x00000a6=166 : **** next IFD offset 25242(+ 12 = 0x62a6/25254)
@0x00000aa=170 : ============= VALUES, IFD 0 ============
@0x00000aa=170 : ImageDescription = 'SONY
DSC \0'
@0x00000c8=200 : Make =
'SONY \0'
@0x00000d8=216 : Model = 'DSLR-A100\0'
@0x00000e2=226 : XResolution = 72
@0x00000ea=234 : YResolution = 72
@0x00000f2=242 : Software = 'DSLR-A100
v1.04\0'
@0x0000102=258 : DateTime = '2008:05:23
00:46:51\0'
@0x0000192=402 : (in IFD 0) 36 entries
starting at file offset 0x194=404
@0x0000194=404 : <0x829a=33434> ExposureTime
[5 =RATIONAL 1] = @0x370=880
@0x00001a0=416 : <0x829d=33437> FNumber
[5 =RATIONAL 1] = @0x378=888
@0x00001ac=428 : <0x8822=34850> ExposureProgram
[3 =SHORT 1] = 2 = 'Normal'
@0x00001b8=440 : <0x8827=34855> ISOSpeedRatings
[3 =SHORT 1] = 400
@0x00001c4=452 : <0x9000=36864> Version
[7 =UNDEFINED 4] = '0221'
@0x00001d0=464 : <0x9003=36867> DateTimeOriginal
[2 =ASCII 20] = @0x348=840
@0x00001dc=476 : <0x9004=36868> DateTimeDigitized
[2 =ASCII 20] = @0x35c=860
@0x00001e8=488 : <0x9101=37121> ComponentsConfiguration
[7 =UNDEFINED 4] = 1,2,3,0 = 'YCbCr'
@0x00001f4=500 : <0x9102=37122> CompressedBitsPerPixel
[5 =RATIONAL 1] = @0x380=896
@0x0000200=512 : <0x9203=37379> BrightnessValue
[10=SRATIONAL 1] = @0x3a8=936
@0x000020c=524 : <0x9204=37380> ExposureBiasValue
[10=SRATIONAL 1] = @0x388=904
@0x0000218=536 : <0x9205=37381> MaxApertureValue
[5 =RATIONAL 1] = @0x390=912
@0x0000224=548 : <0x9207=37383> MeteringMode
[3 =SHORT 1] = 5 = 'Pattern'
@0x0000230=560 : <0x9208=37384> LightSource
[3 =SHORT 1] = 0 = 'unknown'
@0x000023c=572 : <0x9209=37385> Flash
[3 =SHORT 1] = 24 = 'no flash - auto'
@0x0000248=584 : <0x920a=37386> FocalLength
[5 =RATIONAL 1] = @0x398=920
@0x0000254=596 : <0x9214=37396> SubjectArea
[3 =SHORT 4] = @0x3b0=944
@0x0000260=608 : <0x927c=37500> MakerNote
[7 =UNDEFINED 24208] = @0x3f8=1016
@0x000026c=620 : <0x9286=37510> UserComment
[7 =UNDEFINED 64] = @0x3b8=952
@0x0000278=632 : <0xa000=40960> FlashPixVersion
[7 =UNDEFINED 4] = '0100'
@0x0000284=644 : <0xa001=40961> ColorSpace
[3 =SHORT 1] = 1 = 'sRGB'
@0x0000290=656 : <0xa002=40962> PixelXDimension
[4 =LONG 1] = 3872
@0x000029c=668 : <0xa003=40963> PixelYDimension
[4 =LONG 1] = 2592
@0x00002a8=680 : <0xa005=40965> Interoperability
[4 =LONG 1] = @0x6288=25224
@0x00002b4=692 : <0xa300=41728> FileSource
[7 =UNDEFINED 1] = 3 = 'DSC'
@0x00002c0=704 : <0xa301=41729> SceneType
[7 =UNDEFINED 1] = 1 = 'direct photo'
@0x00002cc=716 : <0xa401=41985> CustomRendered
[3 =SHORT 1] = 0 = 'Normal'
@0x00002d8=728 : <0xa402=41986> ExposureMode
[3 =SHORT 1] = 0 = 'Auto'
@0x00002e4=740 : <0xa403=41987> WhiteBalance
[3 =SHORT 1] = 0 = 'Auto'
@0x00002f0=752 : <0xa404=41988> DigitalZoomRatio
[5 =RATIONAL 1] = @0x3a0=928
@0x00002fc=764 : <0xa405=41989> FocalLengthIn35mmFilm
[3 =SHORT 1] = 105mm
@0x0000308=776 : <0xa406=41990> SceneCaptureType
[3 =SHORT 1] = 0 = 'Standard'
@0x0000314=788 : <0xa407=41991> GainControl
[3 =SHORT 1] = 1 = 'Low gain up'
@0x0000320=800 : <0xa408=41992> Contrast
[3 =SHORT 1] = 0 = 'Normal'
@0x000032c=812 : <0xa409=41993> Saturation
[3 =SHORT 1] = 0 = 'Normal'
@0x0000338=824 : <0xa40a=41994> Sharpness
[3 =SHORT 1] = 0 = 'Normal'
@0x0000344=836 : **** next IFD offset 0
@0x0000348=840 : ============= VALUES, EXIF IFD ============
@0x0000370=880 : ExposureTime = 4 sec
@0x0000378=888 : FNumber = 5.6 APEX =
'f7.0'
@0x0000348=840 : DateTimeOriginal = '2008:05:23
00:46:51\0'
@0x000035c=860 : DateTimeDigitized = '2008:05:23
00:46:51\0'
@0x0000380=896 : CompressedBitsPerPixel = 8
@0x00003a8=936 : BrightnessValue = -3.88 APEX =
'0.0679 foot lambert'
@0x0000388=904 : ExposureBiasValue = 0 APEX
@0x0000390=912 : MaxApertureValue = 4.97 APEX =
'f5.6'
@0x0000398=920 : FocalLength = 70 mm
@0x00003b0=944 : SubjectArea =
1936,1296,329,393
@0x00003f8=1016 : length 24208, ID scheme,
28 entries starting at offset 0x406/1030
@0x00003f8=1016 : MakerNoteId = 'SONY DSC '
@0x0000406=1030 : <0X2000= 8192> TAG_0X2000
[ 7=UNDEFINED 1] = 0
@0x0000412=1042 : <0XB000=45056> TAG_0XB000
[ 1=BYTE 4] = 0,0,0,2
@0x000041e=1054 : <0XB001=45057> TAG_0XB001
[ 3=SHORT 1] = 256
@0x000042a=1066 : <0XB020=45088> TAG_0XB020
[ 2=ASCII 9] = @0x55a=1370
@0x0000436=1078 : <0XB040=45120> TAG_0XB040
[ 3=SHORT 1] = 65535
@0x0000442=1090 : <0XB041=45121> TAG_0XB041
[ 3=SHORT 1] = 65535
@0x000044e=1102 : <0XB042=45122> TAG_0XB042
[ 3=SHORT 1] = 65535
@0x000045a=1114 : <0XB043=45123> TAG_0XB043
[ 3=SHORT 1] = 65535
@0x0000466=1126 : <0XB044=45124> TAG_0XB044
[ 3=SHORT 1] = 65535
@0x0000472=1138 : <0XB045=45125> TAG_0XB045
[ 3=SHORT 1] = 65535
@0x000047e=1150 : <0XB046=45126> TAG_0XB046
[ 3=SHORT 1] = 65535
@0x000048a=1162 : <0XB047=45127> TAG_0XB047
[ 3=SHORT 1] = 65535
@0x0000496=1174 : <0XB048=45128> TAG_0XB048
[ 8=SSHORT 1] = 65535
@0x00004a2=1186 : <0XB049=45129> TAG_0XB049
[ 3=SHORT 1] = 65535
@0x00004ae=1198 : <0XB04A=45130> TAG_0XB04A
[ 3=SHORT 1] = 65535
@0x00004ba=1210 : <0XB04B=45131> TAG_0XB04B
[ 3=SHORT 1] = 65535
@0x00004c6=1222 : <0XB04C=45132> TAG_0XB04C
[ 5=RATIONAL 1] = @0x56a=1386
@0x00004d2=1234 : <0XB04D=45133> TAG_0XB04D
[ 3=SHORT 1] = 65535
@0x00004de=1246 : <0XB04E=45134> TAG_0XB04E
[ 3=SHORT 1] = 65535
@0x00004ea=1258 : <0XB021=45089> TAG_0XB021
[ 4=LONG 1] = 0
@0x00004f6=1270 : <0XB022=45090> TAG_0XB022
[ 4=LONG 1] = 0
@0x0000502=1282 : <0XB023=45091> TAG_0XB023
[ 4=LONG 1] = 16
@0x000050e=1294 : <0XB024=45092> TAG_0XB024
[ 4=LONG 1] = 0
@0x000051a=1306 : <0XB025=45093> TAG_0XB025
[ 4=LONG 1] = 0
@0x0000526=1318 : <0XB026=45094> TAG_0XB026
[ 4=LONG 1] = 1
@0x0000532=1330 : <0XB027=45095> TAG_0XB027
[ 4=LONG 1] = 40
@0x000053e=1342 : <0XB028=45096> TAG_0XB028
[ 4=LONG 1] = 1382
@0x000054a=1354 : <0XB029=45097> TAG_0XB029
[ 4=LONG 1] = 0
@0x0000556=1366 : no next IFD offset used
@0x0000556=1366 : ============= VALUES, MakerNote ============
*0x0000571=1393 : ---- End of values before end of MakerNote
0x0000572=1394 : 00 17 00 00 00 07 00 00 00 04 4d 4c
|..........ML|
0x000057e=1406 : 54 30 00 10 00 07 00 00 01 00 00 00
|T0..........|
0x000058a=1418 : 07 84 00 18 00 07 00 00 10 00 00 00
|............| etc... (use -M to see more)
@0x0006287=25223 :

@0x00003b8=952 : UserComment =
length 56+8: (CC=undefined) = (56 nulls)
@0x0006288=25224 : 2 entries
starting at file offset 0x628a=25226
@0x000628a=25226 : <0x0001= 1>
InteroperabilityIndex [2 =ASCII 4] = 'R98'
@0x0006296=25238 : <0x0002= 2>
InteroperabilityVersion [7 =UNDEFINED 4] = '0100'
@0x00062a2=25250 : **** next IFD offset 0
@0x00062a5=25253 :

@0x00003a0=928 : DigitalZoomRatio = 0
-0x00062a5=25253 :

@0x0000116=278 : Version 0300, size 124, 6
entries
@0x0000126=294 : PIM_0X0001 = 00 16 00 16 |....| =
0x160016/1441814
@0x000012c=300 : PIM_0X0002 = 01 00 00 00 |....| =
0x1000000/16777216
@0x0000132=306 : PIM_0X0003 = 00 00 00 34 |...4| =
0x34/52
@0x0000138=312 : PIM_0X0100 = 05 00 00 00 |....| =
0x5000000/83886080
@0x000013e=318 : PIM_0X0101 = 00 00 00 00 |....| = 0/0
@0x0000144=324 : PIM_0X0110 = 80 00 00 00 |....| =
0x80000000/2147483648
*0x000014a=330 : ---- End of values before end of
PrintIM section
-0x0000191=401 :

@0x00062a5=25253 :

@0x00062a6=25254 : 8 entries starting at file offset
0x62a8=25256
@0x00062a8=25256 : <0x0103= 259> Compression
[3 =SHORT 1] = 6 = 'Exif/old JPEG'
@0x00062b4=25268 : <0x0112= 274> Orientation
[3 =SHORT 1] = 1 = '0,0 is top left'
@0x00062c0=25280 : <0x011a= 282> XResolution
[5 =RATIONAL 1] = @0x630c=25356
@0x00062cc=25292 : <0x011b= 283> YResolution
[5 =RATIONAL 1] = @0x6314=25364
@0x00062d8=25304 : <0x0128= 296> ResolutionUnit
[3 =SHORT 1] = 2 = 'pixels per inch'
@0x00062e4=25316 : <0x0201= 513> JPEGInterchangeFormat
[4 =LONG 1] = @0x9d72=40306
@0x00062f0=25328 : <0x0202= 514> JPEGInterchangeFormatLength
[4 =LONG 1] = 2576
@0x00062fc=25340 : <0x0213= 531> YCbCrPositioning
[3 =SHORT 1] = 1 = 'centered'
@0x0006308=25352 : **** next IFD offset 0
@0x000630c=25356 : ============= VALUES, IFD 1 ============
@0x000630c=25356 : XResolution = 72
@0x0006314=25364 : YResolution = 72
@0x0009d72=40306 : #### Start of JPEG thumbnail data for IFD 1,
length 2576 ####
@0x0009d72=40306 :
@0x0009d74=40308 : length 197
@0x0009e3b=40507 : length 418 table class = 0
table id = 0
@0x0009fdf=40927 : length 17, 8 bits/sample,
components=3, width=160, height=120
@0x0009ff2=40946 : length 12 start of JPEG data,
3 components 19200 pixels
@0x000a780=42880 : JPEG length 2576
@0x000a781=42881 : #### End of JPEG thumbnail data for
IFD 1, length 2576 ####
@0x000a781=42881 :

-0x000d1b4=53684 :

@0x000d1b5=53685 : length 132
@0x000d23b=53819 : length 418 table class = 0 table id = 0
@0x000d3df=54239 : length 17, 8 bits/sample,
components=3, width=3872, height=2592
@0x000d3f2=54258 : length 12 start of JPEG data, 3
components 10036224 pixels
@0x02653a1=2511777 : JPEG length 2511779
-0x02653a2=2511778 : END OF FILE
@000000000=0 : Start of JPEG baseline DCT compressed primary
image [3872x2592] length 2511779
-0x02653a2=2511778 : End of JPEG primary image data
@0x0009d72=40306 : Start of JPEG baseline
DCT compressed reduced-resolution image [160x120] length 2576 (IFD 1)
-0x000a781=42881 : End of JPEG reduced-resolution image data
Number of images = 2
File Format = JPEG/APP1/TIFF/EXIF # with MakerNote (Sony [-1])

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

jxc
Offline
Joined: 2005-02-24
Points: 0

Hi Fabrizio,

You seemed to be using the Java-SE built-in JPEG reader particularly.
When I tried your test case with jai-imageio, the other JPEG reader,
com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader,
could read the thumbnail successfully.

HTH,
-James

Fabrizio Giudici

jai-imageio@javadesktop.org wrote:
> Hi Fabrizio,
>
> You seemed to be using the Java-SE built-in JPEG reader particularly.
> When I tried your test case with jai-imageio, the other JPEG reader,
> com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader,
> could read the thumbnail successfully.
>
>
Yes, I know that (sorry I didn't specify it clearly), it's that I have
troubles with the native library (troubles not related to JAI but to the
integration in my specific context, something that I'm willing to solve
but not in the short term) and I'd like to know if the thing could be
fixed with the Java-SE in some way.

Thanks.

--
f.g.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

jxc
Offline
Joined: 2005-02-24
Points: 0

I see. Then, this is probably not the best forum for the question.
JAVA2D-INTEREST@JAVA.SUN.COM might be the right mailing
list for this question.

Thanks,
-James

Fabrizio Giudici

jai-imageio@javadesktop.org wrote:
> I see. Then, this is probably not the best forum for the question.
> JAVA2D-INTEREST@JAVA.SUN.COM might be the right mailing
> list for this question.

Thank you - but can this be confirmed? I believed the Java2D list is for
image manipulation, not I/O.

Thanks.

--
f.g.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

jxc
Offline
Joined: 2005-02-24
Points: 0

You can try JAVA-IMAGEIO-INTEREST@JAVA.SUN.COM, but it
has been very quiet recently:
http://archives.java.sun.com/cgi-bin/wa?A0=java-imageio-interest

AFAIK, Java Image I/O was developed by the Java2D group. See
http://openjdk.java.net/groups/2d/

Thanks,
-James

robert engels

You can decode the image, and check the buffered image type - which
would be slow...

The other is to just read the metadata and parse, look at the
compression field.

On Aug 29, 2008, at 5:17 PM, jai-imageio@javadesktop.org wrote:

> I have been look for a way to read in a TIFF image and determine if
> it is a bilevel (black and white) image. So far from reading the
> forums and searching on google I have not been able to find
> anything. I have no idea where to even begin at this point.
>
> Any suggestions on how to accomplish this will be most appreciated.
> [Message sent by forum member 'dbuddeii' (dbuddeii)]
>
> http://forums.java.net/jive/thread.jspa?messageID=296274
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

dbuddeii
Offline
Joined: 2008-08-29
Points: 0

> You can decode the image, and check the buffered image type -
> which would be slow...

Please keep in mind I only have a very mild understanding of image manipulation. First question on this, does this guarantee more accuracy over checking the metadata? My understanding is that metadata is up to whomever/whatever progam was used to create the image to place the metadata in the image.

If I can trust the metadata, could you point to me any examples of how to parse the metadata? If I cannot trust the metadata, can you point to me an example of how to check the buffered image?

Thanks in advance for your help.

robert engels

Depends, if you eventually need to process the image, setting the
ImageType when reading is your best best.

Much of the metadata is not really stored, but calculated based on
other fields in the image.

For things like the image type, I think you are pretty safe -
otherwise the decoders probably would not function.

Read the ImageIO overview for processing metadata...

On Sep 2, 2008, at 1:29 PM, jai-imageio@javadesktop.org wrote:

>> You can decode the image, and check the buffered image type -
>> which would be slow...
>
> Please keep in mind I only have a very mild understanding of image
> manipulation. First question on this, does this guarantee more
> accuracy over checking the metadata? My understanding is that
> metadata is up to whomever/whatever progam was used to create the
> image to place the metadata in the image.
>
> If I can trust the metadata, could you point to me any examples of
> how to parse the metadata? If I cannot trust the metadata, can you
> point to me an example of how to check the buffered image?
>
> Thanks in advance for your help.
> [Message sent by forum member 'dbuddeii' (dbuddeii)]
>
> http://forums.java.net/jive/thread.jspa?messageID=296751
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net