Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem in saving figures including lines in XOR erase mode

Subject: Problem in saving figures including lines in XOR erase mode

From: safiye

Date: 8 Aug, 2012 05:58:12

Message: 1 of 7

Hi all,

I create a figure using MATLAB code. There are lines on the figure with erase mode 'xor'. I save this figure as a .png image using MATLAB code. But the xor mode of the original figure is ignored and not saved. That's, when I open the saved .png image, the line colors are constant everywhere, they're not changing according to the background color on different points of the image. I tried it using figure's File->Saveas menu and Edit->Copy Figure menu but nothing changed. I also tried different types of extensions including .eps, but none saved the xor mode except .fig (because I will import the saved figure into latex document,.fig extension does not serve for me). How is it possible to save the figure as I see it on the screen? I think there must be a way and googled it a lot, but it was useless. Below is an example code:

deneme = double(rand(20, 20) < 0.5);
figure;
pcolor(deneme);
colormap(flipud(gray));
line([1 20], [10 10], 'color', 'm', 'lineStyle','--','erasemode','xor', 'linew', 3);
line([9 9], [1 20], 'color', 'm', 'lineStyle','--','erasemode','xor', 'linew', 3);
set(gcf, 'PaperPositionMode', 'auto');
saveas(gcf, 'C:\Users\scelik\Desktop\deneme.png', 'png');

Thanks in advance.

Subject: Problem in saving figures including lines in XOR erase mode

From: Bruno Luong

Date: 8 Aug, 2012 06:26:14

Message: 2 of 7

"safiye" wrote in message <jvsv5k$im5$1@newscl01ah.mathworks.com>...
>
> deneme = double(rand(20, 20) < 0.5);
> figure;
> pcolor(deneme);
> colormap(flipud(gray));
> line([1 20], [10 10], 'color', 'm', 'lineStyle','--','erasemode','xor', 'linew', 3);
> line([9 9], [1 20], 'color', 'm', 'lineStyle','--','erasemode','xor', 'linew', 3);
> set(gcf, 'PaperPositionMode', 'auto');
> saveas(gcf, 'C:\Users\scelik\Desktop\deneme.png', 'png');

This piece of code works to me, when I open the png file there are two pink lines. My config 2010A-64 Windows 7.

Bruno

Subject: Problem in saving figures including lines in XOR erase mode

From: safiye

Date: 8 Aug, 2012 06:53:11

Message: 3 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jvt0q6$n5h$1@newscl01ah.mathworks.com>...
> "safiye" wrote in message <jvsv5k$im5$1@newscl01ah.mathworks.com>...
> >
> > deneme = double(rand(20, 20) < 0.5);
> > figure;
> > pcolor(deneme);
> > colormap(flipud(gray));
> > line([1 20], [10 10], 'color', 'm', 'lineStyle','--','erasemode','xor', 'linew', 3);
> > line([9 9], [1 20], 'color', 'm', 'lineStyle','--','erasemode','xor', 'linew', 3);
> > set(gcf, 'PaperPositionMode', 'auto');
> > saveas(gcf, 'C:\Users\scelik\Desktop\deneme.png', 'png');
>
> This piece of code works to me, when I open the png file there are two pink lines. My config 2010A-64 Windows 7.
>
> Bruno

Yes, there are two pink lines, but what I need is pink lines on white squares, and green lines on black squares, that's what the XOR mode does so that all lines are more visible everywhere on the image. You must have seen green dashed lines on black parts on the opened image. But those green line parts disappear when we save the image, and all is pink (magenta), the color I specify when I draw the line.

Thanks.

Subject: Problem in saving figures including lines in XOR erase mode

From: Bruno Luong

Date: 8 Aug, 2012 07:25:14

Message: 4 of 7

I see the problem now.

Subject: Problem in saving figures including lines in XOR erase mode

From: safiye

Date: 8 Aug, 2012 10:20:21

Message: 5 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jvt48q$3ju$1@newscl01ah.mathworks.com>...
> I see the problem now.


Is there any way you can think of then? I think those pink-green lines are just a temporary representation and MATLAB does not keep the pixel information of the result of XOR.

Subject: Problem in saving figures including lines in XOR erase mode

From: Bruno Luong

Date: 8 Aug, 2012 12:27:09

Message: 6 of 7

"safiye" wrote in message <jvteh5$2o6$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jvt48q$3ju$1@newscl01ah.mathworks.com>...
> > I see the problem now.
>
>
> Is there any way you can think of then? I think those pink-green lines are just a temporary representation and MATLAB does not keep the pixel information of the result of XOR.

The behavior is actually documented, they recommend using GETFRAME to capture the figure (with worse quality I'm afraid). Here is the highlight of the doc:

[ Printing with Nonnormal Erase Modes

MATLAB always prints figures as if the EraseMode of all objects is normal. This means graphics objects created with EraseMode set to none, xor, or background can look different on screen than on paper. On screen, MATLAB mathematically combines layers of colors (for example, performing an XOR on a pixel color with that of the pixel behind it) and ignore three-dimensional sorting to obtain greater rendering speed. However, these techniques are not applied to the printed output.

You can use the getframe command or other screen capture applications to create an image of a figure containing nonnormal mode objects. ]

Bruno

Subject: Problem in saving figures including lines in XOR erase mode

From: safiye

Date: 9 Aug, 2012 06:29:16

Message: 7 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jvtlut$oae$1@newscl01ah.mathworks.com>...
> "safiye" wrote in message <jvteh5$2o6$1@newscl01ah.mathworks.com>...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jvt48q$3ju$1@newscl01ah.mathworks.com>...
> > > I see the problem now.
> >
> >
> > Is there any way you can think of then? I think those pink-green lines are just a temporary representation and MATLAB does not keep the pixel information of the result of XOR.
>
> The behavior is actually documented, they recommend using GETFRAME to capture the figure (with worse quality I'm afraid). Here is the highlight of the doc:
>
> [ Printing with Nonnormal Erase Modes
>
> MATLAB always prints figures as if the EraseMode of all objects is normal. This means graphics objects created with EraseMode set to none, xor, or background can look different on screen than on paper. On screen, MATLAB mathematically combines layers of colors (for example, performing an XOR on a pixel color with that of the pixel behind it) and ignore three-dimensional sorting to obtain greater rendering speed. However, these techniques are not applied to the printed output.
>
> You can use the getframe command or other screen capture applications to create an image of a figure containing nonnormal mode objects. ]
>
> Bruno


Thanks a lot. Yes it works, but the image quality is highly lower than the one of the saveas's result. I think choosing a light color for lines will be the way I will use instead of using xor erase mode to make lines visible everywhere.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us