|
From: Daniel J S. <dan...@ie...> - 2006-02-20 13:03:12
|
Petr,
I'm having problems plotting an image via
imshow(r,g,b)
in Octave. There may be multiple bugs and I can't seem to reproduce things exactly in pure gnuplot, even using the files that Octave creates.
It began in a case where image(r,g,b) worked OK in x11, but not with the postscript terminal. The bug was causing gnuplot to crash.
In Octave, currently, image(r,g,b) is done using a palette as opposed to true color.
I think it is too difficult to describe what I did for that, but then I started sniffing around and found this: In octave type (with x11 terminal)
A = loadimage ("default.img");
image(A); # no problem
imshow(A,A,A); # I see a crash
image(A); # continues to crash
imshow(A); # seems to fix problem
image(A); # works again
I think I have traced this bug to the routine interpolate_color_from_gray(). To verify this, replace the couple commands:
/* find index, bisecting would be faster */
for (idx = 0; sm_palette.gradient[idx].pos < gray; ++idx)
; /* do nothing */
with
/* find index, bisecting would be faster */
for (idx = 0; sm_palette.gradient[idx].pos < gray; ++idx)
// ; /* do nothing */
if (idx == maxidx)
fprintf(stderr,"interp 2, %d %d\n", maxidx, idx);
fprintf(stderr,"interp 3, %d %d\n", maxidx, idx);
and you will see that when imshow(A,A,A) is issued in Octave idx = maxidx, which is one beyond the limits of the array and the next fprintf("interp 3") doesn't execute.
Attached is a patch to fix this bug. It uses a bisecting method. Please check it over and test it. You'll find that the imshow(A,A,A) now works but doesn't look to be the correct brightness. We'll address that problem next.
Thanks,
Dan
|