Output of -RGBimage seems to have changed, any help?
Show older comments
I have worked on a function (applyhatch_plusC) which has been on the file 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 appears to 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...
9 Comments
KALYAN ACHARJYA
on 27 Aug 2018
Share the file exchange link? Which Matlab version you are using?
Brian Katz
on 29 Aug 2018
Edited: Walter Roberson
on 29 Aug 2018
Brian Katz
on 14 Sep 2019
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?
Brian Katz
on 17 Sep 2019
Brian Katz
on 25 Nov 2020
Walter Roberson
on 26 Nov 2020
I wonder if it helps to turn off graphics smoothing?
Brian Katz
on 26 Nov 2020
Try the below both with graphics smoothing on and off.
The [38 38 38] you are seeing is due to the default XColor and YColor for the tick marks and text.
Your countEntries appears to be from a file exchange submission https://www.mathworks.com/matlabcentral/fileexchange/23661-violin-plots-for-plotting-multiple-distributions-distributionplot-m so I substituted standard code for that part.
fig = gcf;
ax = axes(fig);
bar(ax, rand(1,3)); % create simple 1 color bar graph
%set(fig,'GraphicsSmoothing','off')
ax.XColor = [0 0 0];
ax.YColor = [0 0 0];
fr = getframe(ax);
getf_r = fr.cdata(:,:,1);getf_g = fr.cdata(:,:,2);getf_b = fr.cdata(:,:,3);getf_rgb = [getf_r(:) getf_g(:) getf_b(:)];
[uniqueEntries,~,G] = unique(getf_rgb,'rows');
numberOfOccurences = accumarray(G, 1);
uniqueEntries
numberOfOccurences
Accepted Answer
More Answers (2)
Image Analyst
on 18 Sep 2019
0 votes
Maybe try the attached MaximizeFigureWindow function first, and then call either saveas(), imwrite(), or (on the File Exchange) export_fig
Image Analyst
on 25 Nov 2020
Try
theImage = getimage(gca);
or else
frame = getframe(gcf)
figure;
imshow(frame.cdata);
axis off
3 Comments
Brian Katz
on 25 Nov 2020
Image Analyst
on 25 Nov 2020
Can you give a small example with an actual RGB image that you synthesize? Be aware that if you use something like plot() over the image, it will antialias the line so that line won't be that one single color that you drew it in.
Brian Katz
on 26 Nov 2020
Edited: Brian Katz
on 26 Nov 2020
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!