How can I print out a large table of symbols from MATLAB to form a cross-stitch chart? - matlab

On this website, one can create stitch charts from images. I'm trying to do this in MATLAB. I have implemented everything using the Image Processing Toolbox (Reducing of number of the colors, mapping to the color space of available yarn colors). I'm done with all of this, the only thing I still need to do is to create an output similar to these files from MATLAB, which basically show which yarn to use for each raster point of the stitch chart:
BW
Color
My question is how to print a table with a lot of very small fields with the color and/or symbol inside.
It should look somehow like in these PDF files. How can I print out a table like this? Directly from MATLAB? Can I create a PDF file like this in MATLAB? Should I export it to Excel somehow?

For the "color" PDF you linked, this looks just like a pixelated image. Why don't you save each "field" as one pixel, for example in a TIF file using imwrite(I, 'filename')? You could then print this TIF into a PDF using an appropriate scaling factor to make the pixels large enough.
For the "BW" PDF which basically contains a large table of symbols, it would probably be easiest to go through HTML or RTF file format to get the table of symbols, and then use some html2pdf or rtf2pdf converter...

Related

Publication ready figures-Matlab [duplicate]

This question already has answers here:
How can I plot professional quality graphs in matlab? [closed]
(2 answers)
Closed 2 years ago.
I want to create high-quality figures ready to be submitted for publication. What is the best font size, type of file to be saved as(.fig, .eps, .png?) and generally the characteristics required for a top-quality figure?
Depends on the paper editing software you use.
If you use Latex or Overleaf, exporting to PDF is the easiest/simplest/smallest-file-size one while keeping image quality as high as possible (i.e. vector format). My typical workflow is
create the plot, set font size to 18 o 20 use set(gca,'fontsize',..).
set(gcf,'paperpositionmode','auto'); this is important! it makes your figure what-you-see-is-what-you-get, so you can adjust figure sizes relative to the font size.
save as PDF or print -dpdf to export to the figure.
call pdfcrop yourfigure.pdf to remove the margins, pdfcrop is available on Linux/Mac, but also available on Windows. If you can't install pdfcrop, you can also use inkscape to fit plot to page.
I usually try to make the figure in its final look using matlab commands (so it can be easily reproduced), but in case there are changes that I can;t make automatically, I will open the pdf using inkscape and manually edit.
if the figure is a 3D surface/mesh rendering with transparency, I will directly call print -dpng -r300 myfile.png to create a png bitmap image directly. Exporting to pdf generates huge file sizes and slow rendering.
once done, upload the pdf or png to overleaf, the platform accepts these formats directly.
If using older versions of MS Word, I had been exporting images to EPS and insert to keep the images in highest quality possible. However, since 2017, this feature was turned off
https://support.microsoft.com/en-gb/office/support-for-eps-images-has-been-turned-off-in-office-a069d664-4bcf-415e-a1b5-cbb0c334a840
but one can still modify a registry key to turn it on.
Later MS Office accepts svg, which you can export from matlab.

Load PDF Image into MATLAB

I have a PDF of building schematics. I would like to load it into MATLAB, and visualize the image via a GUI, so I can measure distances and such for some calculations.
I have no idea if this is even possible?
Furthermore, the PDF has an embedded scale (i.e. 1 cm = 1 meter). If I can extract this as well, that would be awesome.
I found extractFileText which can be used to extract text, but not much else.
I found the easiest way to do this was to convert the pdf to a image, for example using imagemagick. See this question
If you add an example of the image someone might be able to suggest some ideas for extracting the scale information using image processing.

Differences between these two methods to include Matlab figures in a Powerpoint presentation

I want to include Matlab figures in a Powerpoint presentation. [Note that in other contexts, I usually use LaTeX beamer with .eps files, but here I am obliged to use Powerpoint.]
I know two ways:
Save the image as e.g. a .tiff file and include the image in Powerpoint. The result does not always look sharp and some lines are too thin.
Copy the image directly in Matlab and paste it in Powerpoint. The resulting figure is way nicer. But after exporting the Powerpoint to pdf, it may take some time to load the figure (especially when you included grid minor).
What is the difference between these two methods: is it the well-known bitmap vs. vector image difference or something else? Is there a way to have the quality of the second method but without the problem that is loads slowly?

To imcrop non-textual PDF for Mathematica?

I want to prepare one selection of data from my high-quality PDF document which has no textual elements (just a plot), prepared originally by Matlab.
I do not want to give the whole picture for my collegues because it is too overwhelming.
#1 Tools in Matlab
I know this thread How can I read an image file that is stored in PDF format (much like reading a jpeg file with I = imread('image.jpg')? but I have got denying experiences from my colleagues and to my task PDF should be enough because my data is just a high-quality plot without textual elements.
Most relevant thread is this one How to extract data from pdf file in matlab?
Most attempts are based on extracting PDF to TXT, like How to Read PDF file in Matlab? about pdftotext.
I want now imcrop the PDF such that the output could be used in the time-series analysis of Mathematica here, but I did not find that the default imcrop tool of Matlab is supporting PDF, Crop an Image.
Some findings
Show and Save as PDF based on the answer. I do pdf = Import[filename.pdf]; Show[pdf[[1]], PlotRange -> {{50, 200}, {100, 300}}] and I see a good selected picture in Image viewer, but failure when exporting the picture back to Mathematica seeing the complete picture. Why? PlotRange does not crop but only put a white mask on the top of the picture which can separated etc in Mathematica.
Going from Show to ImageCrop based on this answer. Wrong approach, confusion with ImageTake.
Going from Show to ImageTake based on this answer.
The Show and ImageTake are not injective to each other because ImageTake has at least reversed order of parameters {ymin,ymax}, {xmin,xmax} according to the manual. However, I could not manage to select the correct selection by just reversing the parameters. Why?
Comments for Mathematica
It would be nice if the regions selected would correspond to each other.
Therefore, I would like to have some visual tool to select appropriate area from the figure.
I notice there occurs some aliasing when enlarging the original image.
It would be nice to know how Mathematica handles such cases with ImageTake.
How can you prepare imcrop of PDF image for the time-series toolbox of Mathematica?
I think this question is about image extraction.
However, I extended the question to the thread Better Colormap of Matlab and Image Extraction for Time-Series Toolbox of Mathematica? for Mathematica.
Mathematica will import your pdf as a graphic object which you can 'crop' using plotrange.
pdf = Import[filename.pdf];
Show[pdf[[1]], PlotRange -> {{50, 200}, {100, 300}}]
note the values are {{xmin,xmax},{ymin,ymax}} in "points"
You can also rasterize and then use ImageTake
ImageTake[Rasterize[pdf[[1]]], {10, 100}, {20, 100}]
here the values are {ymin,ymax} , {xmin,xmax} (note the reverse order )
Note the [[1]] here is effectively the page number. I'm pretty sure Import returns a list of pages even if the pdf is a single page.
If you want to actually extract plot data that's a whole other question. For that I'd suggest mathematica.stackexchange.com and provide an example file.

Add text to PDF

I've got an exported version of a MATLAB diagram, similar to the one below. The problem is, that there are no axis captions. It's not possible to export the file again from MATLAB. I need to edit the PDF programmatically and edit about 100 diagrams, all with the same axis positions.
Is there a clean and fast way to paste the Strings X and Y at the corresponding positions in the pdf based on a batch process?
Create a PDF file with the captions. Add that as a background with to the PDF files with pdftk.
if know how to use LaTeX, the pstool package can bring you far on this on, including replacing labels (or actually any text on an eps figure) with TeX symbolic expressions. Neat if you're already working in LaTeX.