Issue Saving image with text overlay to png
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 ‘outputTest ‘,num2str(TestNum),’TubeMidpointCrossSection – Test ‘,num2str(TestNum),’.png’]);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 ‘outputTest ‘,num2str(TestNum),’TubeMidpointCrossSection – Test ‘,num2str(TestNum),’.png’]); 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 ‘outputTest ‘,num2str(TestNum),’TubeMidpointCrossSection – Test ‘,num2str(TestNum),’.png’]); saveas, text, png file, figure, overlaid text MATLAB Answers — New Questions









