Input Vector Graphics into Matlab

269 ビュー (過去 30 日間)
Jim Lehane
Jim Lehane 2013 年 1 月 8 日
コメント済み: Ondrej Pokorny 2016 年 11 月 22 日
Is there anyway to input a vector graphic into Matlab (i.e., an EMF, AI, EPS, etc.). This seems like it should be standard but I haven't found anything.

採用された回答

Jim Lehane
Jim Lehane 2013 年 3 月 4 日
It looks like I got what I wanted by converting the black and white image into a series of coordinates via:
[c1, d1] = find (bwlabel(BW));
Thanks for the help everyone.
  1 件のコメント
Ondrej Pokorny
Ondrej Pokorny 2016 年 11 月 22 日
Could I ask you to describe the solution more in detail? I'm dealing with a similar problem. Thank you.

サインインしてコメントする。

その他の回答 (3 件)

Jan
Jan 2013 年 1 月 9 日
You cannot import vector graphics directly. Please send an enhancement request to TMW.
You can use GhostScript to import a PDF in a wanted resolution and obtain the resulting pixel image. You can of course import an EPS file in text mode, but then the problem remains that most likely you do not just want to import the file, but display it also, such that actually the rendering is the problem. And again GhostScript can be a solution.
Another method is to open an ActiveX object in a Matlab figure, e.g.:
FigH = figure;
h = actxcontrol('AcroPDF.PDF.1', [10, 10, 400, 400], FigH)
h.LoadFile(FileName);
h.move([5, 5, 410, 440]);
h.setZoom(100);
By a similar way a HTML browser window can be embedded into a Matlab figure, such that an SVG-file can be displayed seamlessly (when SVG is supported by the used browser). Unfortunately, these are platform specific commands and there is not Matlab function to do this transparently.
  2 件のコメント
Zoltan
Zoltan 2013 年 2 月 28 日
Where is the source how to use this activeXcontrol object or the others? How do you know for example that h.LoadFile(FileName) the way to load the pdf into it? I really would like to exploit these possibilities.
Jan
Jan 2013 年 3 月 4 日
@Zoltan: To be true: I do not have any idea where this snippet is coming from. I store any of such jewels I find in the forums in a file. After I've found the calling sequence to open the Acrobat-ActiveX-control and got the object "h", the methods() function revealed more details.

サインインしてコメントする。


Daniel Shub
Daniel Shub 2013 年 1 月 9 日
You can definitely import an EPS file (and any other vector graphic that is saved as plain text) by simply reading in the text file as a string. Rendering the graphics object, on the other hand is very difficult. You might be able to hack tex.m to make it display an EPS file in a standard figure window, but I don't know for sure.
  3 件のコメント
Daniel Shub
Daniel Shub 2013 年 1 月 9 日
@Jan you are correct TeX doesn't render anything. The MATLAB function tex.m returns a DVI file and the MATLAB graphic engine knows what to do with the returned DVI file. Since in general the TeX engine can convert an EPS file into a DVI file, I think it might be possible to fool MATLAB.
Jan
Jan 2013 年 1 月 9 日
編集済み: Jan 2013 年 1 月 9 日
A very interesting idea. We should investigate this furtherly. I assumed, that the EPS is not included in the DVI, but during the conversion from DVI to PS or to PDF the contents of the EPS are embedded. On the other hand modern PDFLaTeX interpreters do not create the intermediate DVI anymore for converting TeX code to a PDF.
There is a Java library, which imports SVG files and renders them for the requested pixel size. Then for zooming a new import is required. The same should work for EPS interpreted by GhostScript: We can embed the EPS source in the ApplicationData of the figure and call GhostScript to create the pixel-view for the current resolution. Unfortunately I neither know how to feed GhostScript with a string stored in memory, nor do I know an efficient way to return the pixel image from GhostScript without using the harddisk. But of course this is possible calling the GhostScript library directly and not through the command line interface gswin32c.exe.

サインインしてコメントする。


Azzi Abdelmalek
Azzi Abdelmalek 2013 年 1 月 8 日
編集済み: Azzi Abdelmalek 2013 年 1 月 8 日
You can save your vector graphics as a jpg (or tif,...) file, then read it with imread. I don't think that matlab handles such format
  2 件のコメント
Jim Lehane
Jim Lehane 2013 年 1 月 8 日
編集済み: Jim Lehane 2013 年 1 月 8 日
Yes, I am well aware of that but there is a distinct difference between a jpg and a vector graphic. It stands to reason that if Matlab can export vector graphics, which is pretty straight forward, you should be able to input them and treat them the same as if they were created in Matlab. As it is, you can't equate a formula to a jpg as you can a vector graphic.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 1 月 8 日
編集済み: Azzi Abdelmalek 2013 年 1 月 8 日
Yes, If you don't find these tools in Image Processing Toolbox, I don't think to have heard about such toolbox in matlab. There are expert on image Processing in this forum, they will give their point.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by