MATLAB: print pdf in black/white - matlab

Matlab prints figures in either black/white or color. A black/white print of a figure is NOT the same as a color print tweaked to black/white: every color including the light ones is translated as black. (Light colors that look good on screen or a color printer look horrible on a black/white printer)
I would like to print a PDF file of a figure. My problem is that there doesn't seem to be a PDF driver for MATLAB that outputs black/white rather than color.
See the print command: -dpdf is the PDF driver but it is color.
Is there any way I can do this?
(edit: http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f3-84337.html#f3-99776 shows the interactive way of doing this, but I need a programmatic method, otherwise it will get tedious rather quickly.)

You can fully automate the print process: http://UndocumentedMatlab.com/blog/customizing-print-setup/

You could convert it to an EPS (-deps or -deps2) and then use eps2pdf (which uses GhostScript) to convert that into a PDF. I generally convert all my figures to this way.

Related

Output high-resolution figure from Matlab with full picture

I want to output a high-resolution figure from Matlab.
I tried to "save as pic.eps". But when I insert this picture in latex, it seems that the picture is not "real eps" in the sense that I can tell that the resolution is not enough.
I also tried to "save as pic.pdf". The resolution meets my demand, but the pic is cropped, as it is too large.
Then I used
print -depsc -tiff -r300 -painters pic.eps
This gives me the high-resolution full picture, but some of the dashed lines in the original picture disappeared. I have tried many other cases and still couldn't find the right way to solve my problem. Any suggestions are highly appreciated
I'd try to save eps in vector format, or use a vector only format such as .svg.
For example,
print -depsc2 -painters test.eps
These are the vector graphics supported formats according to the current documentation:
Option Vector Graphics Format File Extension
'-dpdf' Full page Portable Document Format (PDF) color .pdf
'-deps' Encapsulated PostScript (EPS) Level 3 black and white .eps
'-depsc' Encapsulated PostScript (EPS) Level 3 color .eps
'-deps2' Encapsulated PostScript (EPS) Level 2 black and white .eps
'-depsc2' Encapsulated PostScript (EPS) Level 2 color .eps
'-dmeta' Enhanced Metafile (Windows® only) .emf
'-dsvg' SVG (Scalable Vector Graphics) .svg
'-dps' Full-page PostScript (PS) Level 3 black and white .ps
'-dpsc' Full-page PostScript (PS) Level 3 color .ps
'-dps2' Full-page PostScript (PS) Level 2 black and white .ps
'-dpsc2' Full-page PostScript (PS) Level 2 color .ps
you'll also have to use the '-painters' renderer when saving vector graphics files. If you save to a vector graphics file and if the figure RendererMode property is set to 'auto', then print automatically attempts to use the Painters renderer. If you want to ensure that your output format is a true vector graphics file, then specify the Painters renderer. For example:
print('-painters','-deps','myVectorFile')
this command in question may come from the following link
After removing -tiff, my issue of missing one line was fixed (even though I don't understand what is '-tiff' for)

Perl Magick Resize Color Issue

I'm writing a script to resize gif images. I've notice that the images I create have a smaller image size, but take up more room on disk. I think I've tracked down the cause of the problem. The original images when examined in photoshop only have 4 colors in their color table (white, gray, grayer, black) while the new images have 256 colors in their color table. I can't find a way to copy the color table from the incoming image, is there some way to control this? Here's my script
use Image::Magick;
my $image = Image::Magick->new;
$image -> Read( 'test.gif' );
$image -> Resize(geometry=>"50%");
$image->Write( 'test-out.gif' );
Any advice much appreciated.
You can use Sample() instead of Resize() to keep the same number of colours
$image->Sample(geometry=>"50%");
You can limit the number of output colors using the -colors option. It's a good idea to include the +dither option, even if you're sure you have the same number of colors in both input and output. In straight ImageMagick, it would look like this:
convert test.gif +dither -colors 4 test-out.gif
I don't know the syntax for the perlMagick API, but this should get you pretty close.

Matlab imwrite() quality

I'm very new to Matlab, though I know a few other programming languages, so please forgive me if this is something simple. I have not been able to find any answers to this, either on StackOverflow or elsewhere.
I produce a figure using the following code:
figure(6),imageplot(P); drawnow;
Which looks like this:
I then save this image to my computer using the following commands:
imwrite(P, 'images/plot.png');
And the resulting image is tiny, and missing some of the color information:
If, however, I utilize the save function in the open figure (image #1) and save it manually, I get exactly what I want, which is that exact image stored on my computer.
How would I program that? I assumed that imwrite() would just write the image directly, but apparently I'm doing something wrong. Any advice? Perhaps it has something to do with the imageplot command? I cannot seem to get that to work in imwrite.
Update: Based on the comments below, I have begun using "imresize" with the "nearest" option. This scales the image properly, but the resulting image is still curiously darker (and therefore has less information) than if I hit the "save" button in the figure.
Image saved from figure:
Image using "imresize" with "nearest" option:
The MATLAB imwrite command saves exactly the number of pixels as specified in your image matrix. This is the actual result of your computation; the reason the output is "tiny" is because it is supposed to be. To make it larger, would be to simply scale/zoom it as required.
The save figure option however does something quite different: it rasterizes the the output you obtain in the figure window and gives you the option for saving it as an image. This is evident in the fact that when you do so, you obtain a white background in addition to your result which is really just the grey background you see before you save it; this can be adjusted by resizing the figure window before utilizing the save option.
If you're looking to simply make the output figure larger, I would recommend using something along the lines of the imresize command.
Say, if you want the default size to be twice the size of the real result, simply use:
imresize(P, 2.0);
For more options, try help imresize.
The command you need for the "Save As..." functionality of figures is called "print". I often use
print(gcf, '-dpng', 'some_filename.png')
or
print(gcf, '-depsc', 'some_filename.eps','-r0')
to save a figure as it is shown on screen. The format png offers a small filesize and excellent quality, and it is understood by most image viewers and browsers. The eps format is a vector format, which I use for printig. The '-r0' option specifies "use the same size as given by the screen resolution" for the vector format properties.

How to darken postscript text produced by emacs

I'm using emacs command ps-spool-buffer-with-faces command to make some postscript files of code I'm working on. The problem is that the font color seems to be light gray instead of black. I've poked around the postscript file & googled a bit, but have not found any solution. Does anyone know how to turn my gray font black?
Assuming you just want to print in black and white, try:
(setq ps-print-color-p nil)
Otherwise, you might take a look at other values for ps-print-color-p:
ps-print-color-p is a variable defined in `ps-print.el'.
Its value is t
Documentation:
Specify how buffer's text color is printed.
Valid values are:
nil Do not print colors.
t Print colors.
black-white Print colors on black/white printer.
See also `ps-black-white-faces'.
Any other value is treated as t.
You can customize this variable.
You can customize using M-xcustomize-variableRETps-print-color-pRET

How can get PDF::API2 to use CMYK instead of RGB?

I am generating pdfs with Perl and PDF::API2. How can I get my pdf to be CMYK? Currently my pdfs all come out as RGB according to ImageMagick's identify command.
PDF::API2 allows colors to be entered as RGB or CMYK, and will output whatever you pass into it.
To enter a CMYK color, use the pattern %CCMMYYKK instead of #RRGGBB (note the percent sign instead of the number sign).
For example, you can set "true black" as follows:
$content->fillcolor('%000000FF');
PDF::API2::Util also has an undocumented RGBtoCMYK function. I have no idea if it's accurate, and it's undocumented, so use at your own risk, but it might be useful as a one-time way to convert your existing RGB colors to CMYK.