problem on saving within a folder of the figures I'm going to generate

1 次查看(过去 30 天)
I have a problem on saving the figures I go to generate.
Here is the code I am using to save the images:
filePattern_transformation = fullfile(transformation, '*.jpg');
jpegFiles_transformation = dir(filePattern_transformation);
for k_transformation = 1 %:length(jpegFiles_transformation)
baseFileName_transformation = jpegFiles_transformation(k_transformation).name;
% FUNCTION -.........................
[name_figure] = function_transformation(transformation, baseFileName_transformation); % inside the function: name_figure = figure;
destdirectory_name_folder = pwd;
output_image_transformation = sprintf('image_%03d.png', k_transformation);
fulldestination_transformation = fullfile(destdirectory_name_folder, output_image_transformation);
% imwrite(name_figure, fulldestination_transformation);
% saveas(name_figure, fulldestination_transformation)
end
If I use the "saveas" command the code works but it generates me "wrong" figures (see TRANSFORMATION_1.png) with the white border around the image. I need to create an image like "Image_1.jpg," that is, without that white border. For comparison you can see the two attached images ("Image_1.jpg" and "TRANSFORMATION_1.png").
If I use the "imwrite" command it gives me the following error:
Error using imwrite (line 442)
Expected DATA to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was matlab.ui.Figure.
Is there any way to be able to get the correct save? Any solution is appreciated!
  3 个评论
Alberto Acri
Alberto Acri 2023-2-18
Thank you for your reply. I tried with one image but it creates a white outline on the outer edge.
Luca Ferro
Luca Ferro 2023-2-20
according to the documentation it should minimize the white space of the outer edge, apparently it does not in your case. Mind that again accordin to the documentation, windows operating system enforces a minimum window width and a maximum window size. If you specify a figure size outside of those limits, the displayed figure will conform to the limits instead of the size you specified.
Alternatively i know that for plots you can try to use the set command and maybe it can work even if i have some doubts about it:
set(name_figure,'OuterPosition', [left bottom width height])
exeperiment a bit the the values between the square brackets.

请先登录,再进行评论。

回答(1 个)

Sulaymon Eshkabilov
Try exportgraphics() to save the image graphics

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by