RMagick jp2 problem

A

Ara.T.Howard

the following program:

~ > cat tiff2jp2
require 'RMagick'
tiff = ARGV.shift
jp2 = ARGV.shift || tiff.gsub(%r/tiff?/o,'jp2')
img = Magick::Image.read(tiff).first
img.write jp2


results in quite a 'lossy' transformation even though the docs caim a default
compression type of lossless jp2. i've played with both quality and
compression settings and always lose data with this method

however, using this command:

tifftopnm image.tiff | jasper --input-format pnm --output-format jp2 > image.jp2

does NOT lose data so this shows that that jasper jp2 lib IS capable of doing
lossless compresion

any ideas on why this is?

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| "640K ought to be enough for anybody." - Bill Gates, 1981
===============================================================================
 
T

Tim Hunter

any ideas on why this is?
Ara, what release of ImageMagick are you using? What release of the jasper
library?

Do you get the same results from this command?

convert image.tiff image.jp2
 
A

Ara.T.Howard

Ara, what release of ImageMagick are you using? What release of the jasper
library?

tim-

thanks for the reply.

/dmsp/reference/build/RMagick-1.5.0 > uname -srm
Linux 2.4.21-15.ELsmp i686

/dmsp/reference/build/RMagick-1.5.0 > cat /etc/redhat-release
Red Hat Enterprise Linux WS release 3 (Taroon Update 2)

/dmsp/reference/build/RMagick-1.5.0 > ruby -v
ruby 1.8.1 (2003-12-25) [i686-linux]

/dmsp/reference/build/RMagick-1.5.0 > Magick-config --version
6.0.1

/dmsp/reference/build/RMagick-1.5.0 > jasper --version
1.701.0
libjasper 1.701.0

/dmsp/reference/build/RMagick-1.5.0 > ruby -r RMagick -e 'p Magick::Version'
"RMagick 1.5.0"


hopefully all the latest greatest
Do you get the same results from this command?

convert image.tiff image.jp2

yes. this worries me - it's as if the ImageMagick binding to the jasper lib is
incorrectly dealing with compression/quality... as i said before, the jasper
binary handled perfectly and i get ZERO differences when comparing the bands of
a tiff image and one converted via tifftopnm/jasper...

perhaps a post the ImageMagick group would be more appropriate?


btw. the ruby bindings are really cool - good job.

cheers.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| "640K ought to be enough for anybody." - Bill Gates, 1981
===============================================================================
 
T

Tim Hunter

yes. this worries me - it's as if the ImageMagick binding to the jasper
lib is incorrectly dealing with compression/quality... as i said before,
the jasper binary handled perfectly and i get ZERO differences when
comparing the bands of a tiff image and one converted via
tifftopnm/jasper...

Yes, this is almost certainly an IM<->jasper issue. I'll be glad to send
your question to the ImageMagick developers this afternoon. I'll let you
know what I find out.
btw. the ruby bindings are really cool - good job.

Thank you very much!
 
A

Ara.T.Howard

Yes, this is almost certainly an IM<->jasper issue. I'll be glad to send
your question to the ImageMagick developers this afternoon. I'll let you
know what I find out.

thanks alot tim.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| "640K ought to be enough for anybody." - Bill Gates, 1981
===============================================================================
 
T

Tim Hunter

Ara, I received your email at my home address but my reply to your .gov
address bounced(?). Anyway, the ImageMagick developers say that

convert -quality 100 image.tif image.jp2

should do the trick. I see that you've already tried that with
GraphicsMagick, though. The two packages are not entirely identical, so
maybe it will work with ImageMagick.

If it doesn't work then probably you'll get faster & better answers by
posting directly to the (e-mail address removed) mailing list. This is
one you have to join before you can post. The instructions are on the
ImageMagick web site. If you can get the convert command to work but the
conversion doesn't work with RMagick give me a shout and I'll investigate.

Please let me know if there's anything else I can do to help!
 
T

Tim Hunter

convert -quality 100 image.tif image.jp2

(Yeah, I know I shouldn't follow up my own posts.)

The RMagick version of this is

img.write("image.jp2") {self.quality = 100}
 
A

Ara.T.Howard

Ara, I received your email at my home address but my reply to your .gov
address bounced(?). Anyway, the ImageMagick developers say that

convert -quality 100 image.tif image.jp2

yes - i've done this but can subseqently show a diff of the bands using envi
(rsi inc.) or imgcmp (which ships with jasper) - it's bizarre: for the most
part the diff shows all zeros (no difference) but then 20 or 20 pixels will be
different... at this point this discussion is well off topic but i do have
ONE more RMagick specific question to ask:

what is the most __effecient__ (we are dealing with HUGE images) to compare
the raw pixel values of two images using RMagick, eg (not efficient psuedo
code).

tiff_pixels = Image.get_pixels
jp2_pixels = Image.get_pixels

i = 0
tiff_pixels.each do |pixel|
raise "diff @ #{ i } " unless pixel = jp2_pixels
i += 0
end

thanks again.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| "640K ought to be enough for anybody." - Bill Gates, 1981
===============================================================================
 
T

Tim Hunter

what is the most __effecient__ (we are dealing with HUGE images) to
compare the raw pixel values of two images using RMagick, eg (not
efficient psuedo code).

Assuming you want to compare entire images and get a single result, you
can use the channel_compare method to compare individual channels or all
the channels at once.

Or possibly use the composite method with the DifferenceCompositeOp to
produce a difference image.

Any approach where you use Ruby to inspect individual pixels is
going to involve a lot of overhead, since RMagick has to convert each
pixel to a Pixel object. (And Pixel objects are heavier-weight than you'd
imagine.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[RCR] Numeric#of 47
idiot's guide to druby using ssh tunnels 4
parent of TrueClass, FalseClass 9
pthread 2
narray on windows? 1
Class::name 0
pretty exceptions 0
[RCR] Kernel#hostname 0

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top