Issue Saving image with text overlay to png
    14 次查看(过去 30 天)
  
       显示 更早的评论
    
I am having issues saving an image that has been displayed in a figure, with a couple markers plotted at specific coordinates and then text overlaid using the text function. I am trying to safe this off as a png via     saveas(gcf,'filename.png'); and the figure exports but the overlaid text is missing.  The title and the marker points I plotted show up but no text. Below is the figure. 

Attached is the exported png using saveas
My code looks as follows: 
figure; imshow(img,[]);
    hold on;
    plot(Stats(TestNum).Centroid(1),Stats(TestNum).Centroid(2),'b*');
    set(gca, 'ActivePositionProperty', 'OuterPosition');
    [filepath,name,ext] = fileparts(files(TestNum).name);
    title({[];name;['Original Image With Centroid Marked']},'FontSize',FontSize);
    text(20,500,{['Area = ',num2str(Stats(TestNum).Area.*pixel_scale^2,'%3.2f'),'mm^2'];...
        ['Eccentricity = ',num2str(Stats(TestNum).Eccentricity,'%3.2f')];...
        ['Orientation = ',num2str(Stats(TestNum).Orientation,'%3.2f'),char(176)];...
        ['Major Axis Length = ',num2str(Stats(TestNum).MajorAxisLength.*pixel_scale,'%3.2f'),'mm'];...
        ['Minor Axis Length = ',num2str(Stats(TestNum).MinorAxisLength.*pixel_scale,'%3.2f'),'mm']},...
        'Color','white','FontSize',FontSize);
    saveas(gcf,[pwd '\output\Test ',num2str(TestNum),'\TubeMidpointCrossSection - Test ',num2str(TestNum),'.png']);
1 个评论
  Will Reeves
      
 about 4 hours 前
				
      移动:Walter Roberson
      
      
 about 3 hours 前
  
			I have the same problem.  My issue is, like the above, the image I'm writing text on top of is mostly black - I need white text.  Please can "saveas" actually save "WYSIWYG-like"?
回答(3 个)
  Walter Roberson
      
      
 2019-7-16
        I recommend you take a different approach. Instead of plotting on the image and text() on the image, use the Computer Vision insertText and insertShape routines to etch the information into an RGB array. After that is done, imwrite() the array.
0 个评论
  Jia-Sheng Hong
 2020-1-8
        The text do exist after you save it, however, it become black again. You can set the 'BackgroundColor' of the text to white instead of set the text to white, and it should work.
0 个评论
  Will Reeves
      
 about 4 hours 前
        
      编辑:Will Reeves
      
 about 3 hours 前
  
      Sorry!  I knew I once had the answer to this somewhere...
You need to put the line:
set(gcf, 'InvertHardCopy', 'off');
immediatly before issuing the "saveas" command.
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
			
	产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



