Export to eps result is not the same as in the figure
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad
el 17 de Jul. de 2024
Hello. Im working in color image encryption and i have to plot the histogram of the RGB image in a single 3D plot like this (successful big thanks to a user in my previous post named "Voss"). Im using MATLAB 2014b. I attached the image.
image = imread('encrypted image.png');
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
subplot(2,2,1);
imshow(image);
title('Plain Image')
subplot(2,2,2);
imhist(R);
myHist1 = findobj(gca, 'Type', 'Stem');
myHist1.Color = [1 0 0];
xlim([0 255]);
title('Red Channel Histogram')
subplot(2,2,3);
imhist(G);
myHist2 = findobj(gca, 'Type', 'Stem');
myHist2.Color = [0 1 0];
xlim([0 255]);
title('Green Channel Histogram')
subplot(2,2,4);
imhist(B);
myHist3 = findobj(gca, 'Type', 'Stem');
myHist3.Color = [0 0 1];
xlim([0 255]);
title('Blue Channel Histogram')
figure('Position',[10 10 500 500])
ax = gca();
myHist1_new = copyobj(myHist1,ax);
myHist1_new.ZData = myHist1_new.YData;
myHist1_new.YData = 1+zeros(size(myHist1_new.XData));
myHist2_new = copyobj(myHist2,ax);
myHist2_new.ZData = myHist2_new.YData;
myHist2_new.YData = 2+zeros(size(myHist2_new.XData));
myHist3_new = copyobj(myHist3,ax);
myHist3_new.ZData = myHist3_new.YData;
myHist3_new.YData = 3+zeros(size(myHist3_new.XData));
box on
grid on
xlim([0 255])
% ax.XDir = 'reverse'; % to match the xdir in the reference image
ylim([0 4])
zlim([0 2500])
yticks([1 2 3])
yticklabels(["R","G","B"]+" Channel")
view([30 35])
I want to export this 3D figure into a .eps file to include it in my LaTeX document. Sadly, it turns out like this.
I tried to use the export_fig by Yair Altman in https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig, but the result still the same. export_fig also gives the error like this:
Warning: You seem to be using axes that have overlapping/hidden graphic elements.
Setting axes.SortMethod='ChildOrder' may solve potential problems in EPS/PDFexport. Additional info: https://github.com/altmany/export_fig/issues/211.
I tried to implement the suggestion using "set(ax, 'SortMethod', 'ChildOrder')", but it not resolve the problem.
Any help will be appreciated.
Thank you!
1 comentario
Adam Danz
el 17 de Jul. de 2024
Have you tried
exportgraphics(gcf,'myfile.eps','ContentType','Vector')
Respuesta aceptada
Milan Bansal
el 17 de Jul. de 2024
Hi Mohammad,
I understand that you wish to export your 3D figure in MATLAB into a .EPS file and are facing issues with it when imported in LaTeX.
You can use the print function to properly covert the file current figure in MATLAB into a .EPS file. You can use the following code snippet to achive the same.
print('-depsc', 'filename.eps');
Here is a screenshot of how the figure looks when imported in LaTeX.
Please refer to the following documentation link to learn more about saving figure using print function.
Hope this helps!
Más respuestas (1)
Sahas
el 18 de Jul. de 2024
Editada: Sahas
el 18 de Jul. de 2024
As per my understanding, you are using MATLAB R2014b and want to export the 3D histogram made in “.eps” format through the code provided but the “eps” file is distorted and not looking like the histogram plotted by MATLAB.
I was able to verify the issue and could see that the “eps” file image was indeed distorted and like the one you provided.
To execute the code in MATLAB R2014b, I had to modify two lines of it because “yticks” and “yticklabels” came out as functions from MATLAB R2016b onwards.
% yticks([1 2 3])
% yticklabels(['R','G','B']+ 'Channel')
%Correct use of yticks and yticklabel in MATLAB R2014b
set(gca,'YTick',[1 2 3])
set(gca,'yticklabel',({'R Channel','G Channel','B Channel'}))
I was able to improve on the “eps” file quality by using the “print” function.
print('-depsc', '3d_hist.eps');
Alternatively, if you use MATLAB R2014b version onwards the below property of the “axes” would also give you the same result.
ax.SortMethod = "childorder";
I hope this is beneficial!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!