Use SVG plots when Publish-ing to HTML - matlab

This question was posted on Matlab Central (http://goo.gl/MkU8P) but hasn't gotten any answer. I thought someone here might have a lead.
I use publish() quite a bit to produce online class notes. It's working well but frankly, I find the PNG plots to be of awful quality. I've tried setting figureSnapMethod='antialiased' and that's a bit better but I mostly find the result fuzzy.
What would be awesome is to produce SVG plots. Is there any way to do that? I suppose it would have to involve plot2svg somehow (also from File Exchange) since SVG output seems to be only supported for Simulink models. Or perhaps someone has a better solution using some other high quality format.

before using publish you should set some options to change imageForamt. by default it is set to PNG format which is not good for reports, papers, etc. what you need is a vector graphic image, something like an eps or emf file formats. (in such case it does not matter how much you zoom in , it never becomes fuzzy or low resolution).
Any image format that your installed version of Microsoft Office can import, including 'png' , 'jpg', 'bmp',and 'tiff'. If the 'figureSnapMethod' is 'print',then you can also specify 'eps', 'epsc', 'eps2', 'ill', 'meta',and 'pdf'
for HTML output any format publishes successfully
for latex output any format publishes successfully
I suggest you to use eps, it is the best. and remember SVG is not supported in publish. ;)
you should add this part to your command:
'imageFormat','eps'

Related

Training tesseract 4 with images instead of font

I have some questions about making tiff/box files for tesseract 4.
In TrainingTesseract 4.00 document written:
Making Box Files As with base Tesseract, there is a choice between
rendering synthetic training data from fonts, or labeling some
pre-existing images (like ancient manuscripts for example).
But it did not explain how to train with pre-existing images.
I want to train for the Persian language in tesseract 4 (lstm). I have some images from ancient manuscripts and want to train with images and texts instead of font. So I can’t use text2image command. I know that the old format box files will not work for LSTM training.
How can I make tif/box for tessearct 4 lstm then label them and
how to change tesseract commands?
Should I use other tools for generating box files (Given that Persian
language is right to left )?
Should I use fine tuning or train from Scratch?
I was struggling just like you, until I found this github repository:
https://github.com/OCR-D/ocrd-train
It will make your life super easy. All you need to do is to put your images in tif format and your text should have the same image name with extension .gt.txt. It will take care of all the rest for you. (you might need to update the Makefile according to your local machine)
Whether to train from scratch or fine-tune depends on your own language, data and the problem you are trying to solve. For me the fine tunining is what I need cause I am happy with the current performance but need to add upon it.
All the useful details you might need can be found in this answer
1) Use below command to make lstmbox:
tesseract test.tif test-lstmbox -l eng --psm 6 lstmbox
It will make a lstmbox for you but you have to correct the character in box file.
2) You require enough data for training from Scratch So I suggest fine tuning is better option.

How to extract digits (number) using Matlab

At work I have to record a lot of data from png data. Every time I have to manually record the digits (e.g. mean\SD 101.1\11) on the excel sheet and read it with Matlab. Would it be possible that Matlab could directly read the digits from the PNG image, so that lots of work could be saved?
I know it might involve pattern recognition, but still hope that there may be someone who has done this before.
You can make use of Optical Character Recognition (OCR). The code for it is available here

How to Extract part of Image using Matlab

i have not used matlab much, i need to extract the part of Left and Right Coronary Arteries of a heart from a given heart image.
this is my image,
based on morphological operations, this is what i have come up with,
f=imread('heart.jpg');
diam=strel('diamond',19);
line=strel('line',10,90);
linef=imclose(f,line);
line120=strel('line',10,120);
line120f= imclose(f,line120);
bothline=linef+line120f;
diamf=imclose(f,diam);
arterybm=diamf-bothline;
binaryartery= im2bw(arterybm,0);
mask=cast(binaryartery,class(f));
redPlane=f(:,:,1);
greenPlane=f(:,:,2);
bluePlane=f(:,:,3);
maskedRed=redPlane.*mask;
maskedGreen=greenPlane.*mask;
maskedBlue=bluePlane.*mask;
maskedRGBImage=cat(3,maskedRed,maskedGreen,maskedBlue);
subplot(2,3,1);imshow(f);title('Input Image');subplot(2,3,2);imshow(diamf);title('imclose with Diamond Mask');subplot(2,3,3);imshow(bothline);title('imclose with Line 120 and 90 mask');subplot(2,3,4);imshow(arterybm);title('Difference of line and diamond');subplot(2,3,5);imshow(binaryartery);title('Convert to binary image');subplot(2,3,6);imshow(maskedRGBImage);title('Apply mask to input image');
is there any better approach ?
This task is quite a difficult one, worth academic article if you find solution working flawlessly in most cases. My suggestion: search for articles on the topic, and also try "Matlab File Exchange" (http://www.mathworks.com/matlabcentral/fileexchange/). If you are very lucky, someone might have already solved this problem and posted a solution.
Have a look at the Frangi filter (aka ridge-detection filter), it is meant to detect blood vessels.
There is an implementation available on the file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/24409-hessian-based-frangi-vesselness-filter

dealing with ljpeg (lossless jpeg) using matlab

I am dealing now with DDSM database (Digital Database for Screening Mammography) .. its disadvantage is its extension. It is extension is ljpeg (lossless jpeg) which it is very poorly supported extension. I want to read them using matlab or converting them to any other type which is widely supported. thank
I know there is a working version of DDSM's jpeg program for linux at http://www.cs.unibo.it/~roffilli/sw.html
I compiled and tested it. I used the MATLAB code as described here to view the images.
It displays correctly only for some scanners.
As described in the paper http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.111.3846
When properly compiled, the DDSM software outputs the image data as a stream of raw bytes; one then has to normalise these according to the model of digitiser used to image the original films and then create an image file that is readable by one’s image analysis software environment.
*EDIT: *
I found a complete solution that downloads, normalizes (based on the scanner) and converts the DDSM image to PNG format. Dr. Chris Rose wrote that program, please download it on his website
http://microserf.org.uk/academic/Software.html

Matlab: Write text to PDF

I'd like to create a PDF out of my matlab m-function. The PDF should contain some text information which I want to style a bit and one image (which is previously generated as figure). Is there any way? The only thing I found is publish to publish source-code. The only alternative I could think off was to programm the texts into the figure window and than export the whole figure to pdf. Perhaps there's a better way to do it?
Thanks!
I would recommend generating your figure with Matlab, outputting it to eps, then converting the figure to pdf using epstopdf. Then embed your figure in a latex document and generate a pdf with pdflatex.
I know this sounds like an incredibly roundabout way of doing it, but
This is the way I've come to do it after years of experience and it always gives me the best results
Every one of my colleagues does it this way for the same reason
The results will be completely reproducible
You're using Matlab to do what it's good at (making scientific figures) and latex to do what it's good at (formatting documents)
The Matlab code to make the eps of the figure would be like this (supposing your figure is figure 1):
print -depsc2 -f1 -loose my_fig.eps
You could pretty easily write a latex template that uses my_fig.pdf and then run everything from your Matlab using bangouts:
!epstopdf my_fig
!pdflatex mydoc.tex
If you're on Windows, you can connect to Word using 'actxserver', insert and style any text you like into a blank document, copy and paste MATLAB figures into the document, and then save it to PDF. You can do all of that from within MATLAB. The first time you do this it's a pain, as you need to learn quite a bit about the Word Object Model; but once you've done it a couple of times it's very simple and quick, and you can achieve very professional results. You can combine this with using the 'export_fig' that others have mentioned.