print plots to tiff in accurate pixel resolution
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey everybody!
I am currently fighting with the Matlab print function and I don't know how to get the results I need.
The idea is pretty simple: I read 512x512 px images, then do some feature extraction, overlay the features as polygons using patch() and then I want to write the image back in exactly the same resolution.
However
output_size = [512 512];%Size in pixels
resolution = 300;%Resolution in DPI
set(fig,'paperunits','inches','paperposition',[0 0 output_size/resolution]);
print(fig,'-dtiffn',['-r' num2str(resolution)],'-painters',tiff_name_afm)
Does not work. Indeed the output image IS 512x512, but only because of a large white canvas, whilst the image and graph itself is a lot smaller.
Can anyone help me with this?
Best wishes, Chris
댓글 수: 0
채택된 답변
Walter Roberson
2013년 2월 5일
If you are not needing shading, then instead of using patch() to do the overlays, use poly2mask() to convert the polygons to pixel locations, and write the new values into the image array; then imwrite() the result.
If you need transparency then use the alpha equation to calculate the result:
(1-alpha) * background + alpha * foreground
댓글 수: 0
추가 답변 (1개)
Christoph
2013년 2월 5일
댓글 수: 1
Walter Roberson
2013년 2월 5일
Possibly setting PaperSize is needed; maybe PaperPositionMode as well.
Mixing imshow and patch is not responsible for this difficulty. Printing is a pain.
If setting the PaperSize does not work, then you might get more deterministic output from the File Exchange contribution export_fig
Do you really want to print the whole fig, toolbars and all ? If not then you can export_fig() the axis, or you could toss all the drawing inside a uipanel() and export_fig() or print() the uipanel.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!