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

조회 수: 2 (최근 30일)
Brian Katz
Brian Katz 2018년 8월 27일
답변: Brian Katz 2020년 11월 26일
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
Brian Katz
Brian Katz 2020년 11월 26일
This reduced the amount of dithering, but did not toally eliminate it. Here is an example, where you can see the assumed black, blue, and white, but also 2 gray shades being produced (ie some smoothing still occuring):
>> bar(rand(1,3)); % create simple 1 color bar graph
>> set(gcf,'GraphicsSmoothing','off')
>> fr = getframe(gca);
>> getf_r = fr.cdata(:,:,1);getf_g = fr.cdata(:,:,2);getf_b = fr.cdata(:,:,3);getf_rgb = [getf_r(:) getf_g(:) getf_b(:)];
>> [uniqueEntries,numberOfOccurences] = countEntries(getf_rgb,true)
uniqueEntries =
5×3 uint8 matrix
0 0 0
0 0 255
38 38 38
240 240 240
255 255 255
numberOfOccurences =
2099
72531
1623
1
73386
Walter Roberson
Walter Roberson 2020년 11월 26일
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
uniqueEntries = 3×3
0 0 0 0 114 189 255 255 255
numberOfOccurences
numberOfOccurences = 3×1
2319 47846 111103

댓글을 달려면 로그인하십시오.

채택된 답변

Brian Katz
Brian Katz 2020년 11월 26일
Looking more closely, it appears that the no smoothing option (when also applied to the axis Font) works pretty well. I have tested it in combination with print('-RGBImage').
In doing so, I also discovered that the default color for axis text and box is not BLACK, but [0.15 0.15 0.15]. Setting these object properties (XColor,YColor,GridColor,...) finally resolves the whole problem.
Thank you to all for chiming in. I will update by FileExchange submission soon to reflect all this.

추가 답변 (2개)

Image Analyst
Image Analyst 2019년 9월 18일
Maybe try the attached MaximizeFigureWindow function first, and then call either saveas(), imwrite(), or (on the File Exchange) export_fig

Image Analyst
Image Analyst 2020년 11월 25일
Try
theImage = getimage(gca);
or else
frame = getframe(gcf)
figure;
imshow(frame.cdata);
axis off
  댓글 수: 3
Image Analyst
Image Analyst 2020년 11월 25일
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
Brian Katz 2020년 11월 26일
편집: Brian Katz 2020년 11월 26일
Please see my original post for a very simple example using BAR.
What I am looking for is a replacement of the behaviour of the now defunct "hardcopy" function which would create a BMP version of a figure, without dithering/antialias processing, at a desired DPI (so not even a screendump).
For image processing of the figure, to replace colored regions as in the function I wrote, this is no longer possible because the number of colors is both incorrect and unpredictable.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by