MATLAB Answers

0

Output of -RGBimage seems to have changed, any help?

Asked by Brian Katz on 27 Aug 2018
Latest activity Answered by Image Analyst
on 18 Sep 2019 at 1:04
I have worked on a function (applyhatch_plusC) which has been on th fle exchange now for 15years. Recently, the functionality fails.
What seems to be the issue is the print(gcf,'-RGBimage') does not behave as before, and appear sto be doing some internal dithering that I can't seem to turn off. In previous MatLab versions, even back to <2011 with the funtion hardcopy, an RGB copy of a figure (say, containing a red, green, and blue object) would output a cdata matrix of the image, with 5 unique colores (rgb and b&w). I do the same thing now, on the same image, and I get a whole slew of shades, maybe occuring on a few dozen pixels only.
Now, as my work exploits the unique colors to convert 1 color to soemthing else, this no longer works. hardcopy no longe exists, and I don't see how to get print(gcf,'-RGBimage') to accept options. I would like to avoid passing through a temp file, as this requires write access and isn't very elegant.
This is rather frustrating, as this undocumented MatLab change ruins a nice little function that's been download thousands of times...

  5 Comments

Hello? Can anyone help with this question?
The following code produces a [830 x 1184 x 3] array of RGB values in r2019a. Do you expect otherwise?
surf(peaks);
cdata = print(gcf,'-RGBImage');
size(cdata)
When I run the same code in r2014a, I get the error message,
Error using inputcheck>LocalCheckOption (line 342)
Illegal option '-RGBImage' given.
Error in inputcheck (line 86)
opIndex = LocalCheckOption( cur_arg, options );
Error in print (line 166)
[pj, devices, options ] = inputcheck( pj, inputargs{:} );
The first mention of "-RGMImage" in the documentation for print() was in r2014b (as you can see, it's missing in the documentation for r2014a).
So, that conflicts with the idea that this flag worked in 2011, doesn't it?
Dear Adam,
This was written some time ago, using the hidden function hardcopy to get an RGB image dump of a figure window. This disappeared in 2017 (I think) at which point I moved to print with the option -RBGimage. However, as I noted in my original question, the output of this is not the same as with hardcopy, as it seems to perform dithering on the image.
An an example:
bar(rand(1,3)); create simple 1 color bar graph
bits = print(gcf,'-RGBImage');
bits_r = bits(:,:,1);bits_g = bits(:,:,2);bits_b = bits(:,:,3);bits_rgb = [bits_r(:) bits_g(:) bits_b(:)];
unique(bits_rgb,'rows')
cdata should be an RGB version of the orginal figure, comprising only 3 colors (white [background], black [lines], and blue [the bars]). Instead, it contains over 126 different colors, or actually black, white, blue and the rest are shades of gray.
My question is, how to arrive at the previous functionality of hardcopy now that it is gone, and been replaced by print option which doesn't perform the same.
This was my question, not about when the flag RGBimage option appeared in print.
Looking forward to your response to that I can bring this function back to use (unless there is a new MatLab function for hatch-filling polygons).
Cordially,
-Brian

Sign in to comment.

Tags

Products


Release

R2017b

1 Answer

Answer by Image Analyst
on 18 Sep 2019 at 1:04

Maybe try the attached MaximizeFigureWindow function first, and then call either saveas(), imwrite(), or (on the File Exchange) export_fig

  0 Comments

Sign in to comment.