Mercurial > hg > octave-nkf
diff scripts/image/imwrite.m @ 18610:30aa4e85f8d5 stable
Fix writing and reading of multipage images.
* __magick_read__.cc (encode_uint_image): reset the coordinates for each
Magick::Image object so that writing of multipage images (matrices with
non-singleton 4th dimension) work properly. Stride over the extra channels
at the end of each page, to fix writing of multipage RGB and CMYK images.
(read_images): correct stride over each frame for RGB and CMYK images.
* imwrite.m: add tests to write and read multipage grayscale and RGB images.
Reduce size of test images to speed up comparison.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 04 Mar 2014 16:52:00 +0000 |
parents | bfbe5dcc9943 |
children | 0bfbfb05b158 |
line wrap: on
line diff
--- a/scripts/image/imwrite.m +++ b/scripts/image/imwrite.m @@ -114,7 +114,6 @@ endfunction - %% Test input validation %!error imwrite () # Wrong # of args %!error imwrite (1) # Wrong # of args @@ -126,14 +125,52 @@ %!error imwrite ([], "filename.jpg") # Empty img matrix %!error imwrite (spones (2), "filename.jpg") # Invalid sparse img +## test typical usage with normal grayscale and RGB uint8 images %!testif HAVE_MAGICK -%! imw = randi (255, 100, "uint8"); +%! bw = randi (255, 10, "uint8"); +%! rgb = randi (255, 10, 10, 3, "uint8"); %! filename = [tmpnam() ".png"]; %! unwind_protect -%! imwrite (imw, filename); -%! imr = imread (filename); +%! imwrite (bw, filename); +%! bwr = imread (filename); +%! assert (bw, bwr) +%! +%! imwrite (rgb, filename); +%! rgbr = imread (filename); +%! assert (rgb, rgbr) %! unwind_protect_cleanup %! unlink (filename); %! end_unwind_protect -%! assert (imw, imr) +## Test writing of N dimensional images +%!testif HAVE_MAGICK +%! bw = randi (255, 10, 10, 1, 5, "uint8"); +%! rgb = randi (255, 3, 3, 3, 3, "uint8"); +%! filename = [tmpnam() ".tif"]; +%! unwind_protect +%! imwrite (bw, filename); +%! bwr = imread (filename, "Index", "all"); +%! assert (bw, bwr) +%! +%! imwrite (rgb, filename); +%! rgbr = imread (filename, "Index", "all"); +%! assert (rgb, rgbr) +%! +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect + +## test reading and writing of the alpha channel +%!testif HAVE_MAGICK +%! imw = randi (255, 10, "uint8"); +%! alphaw = randi (255, 10, "uint8"); +%! filename = [tmpnam() ".png"]; +%! unwind_protect +%! imwrite (imw, filename, "Alpha", alphaw); +%! [imr, ~, alphar] = imread (filename); +%! assert (imw, imr) +%! assert (alphaw, alphar) +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect +