1

我有大约。100 张图片,我想阅读这些图片,调整大小并使用 matlab 将其保存在 power point 中,是否可以将这些图像保存在 power point 中,并为每张幻灯片提供标题。我正在使用以下代码阅读图像:

for i = 1:numel(pngfiles)
   im{i} = imread(pngfiles{i});
  imrgb{i} = rgb2gray(im{i});
   imrgb_z{i} = imrgb{i}(160:350,280:450);
end
4

3 回答 3

4

在我看来,最好的方法是在 Powerpoint 中使用 VBA 脚本,而不是从 Matlab 操作 ppt。步骤将是

  1. 在文件夹中创建图像列表 - 使用合理的命名方案
  2. 打开PowerPoint;转到 VBA 编辑器 (Alt-F11) 并添加一个包含以下代码行的模块(注意 - 这直接取自https://stackoverflow.com/a/5038907/1967396并进行了最少的编辑):

-

Sub CreatePictureSlideshow( )
  Dim presentation
  Dim layout
  Dim slide

  Dim FSO
  Dim folder
  Dim file
  Dim folderName
  Dim fileType

  ' Set this to point at the folder you wish to import JPGs from
  ' Note: make sure this ends with a backslash \
  fileType = ".jpg"                ' <<< change this to the type you want
  folderName = "c:\somedirectory\" ' <<< change this to the directory you want

  ' setup variables
  Set presentation = Application.ActivePresentation
  ' choose the layout you want: e.g. if the title needs a particular format
  Set layout = Application.ActivePresentation.SlideMaster.CustomLayouts(1) 
  Set FSO = CreateObject("Scripting.FileSystemObject")

  ' Retrieve the folder's file listing and process each file
  Set folder = FSO.GetFolder(folderName)
  For Each file In folder.Files

     ' Filter to only process JPG images
     If LCase(Right(file.Name), 4)) = fileType Then

        ' Create the new slide and delete any pre-existing contents
        Set slide = presentation.Slides.AddSlide(presentation.Slides.count + 1, layout)
        While slide.Shapes.count > 0
          slide.Shapes(1).Delete  ' <<< You might not want to do this is you want to keep the title placeholder
        Wend

        ' Add the picture
        slide.Shapes.AddPicture folderName + file.Name, False, True, 10, 10


        ' Optional: create a textbox with the filename on the slide for reference
        ' alternatively, add text to the title shape

        Dim textBox
        Set textBox = slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 200)
        textBox.TextFrame.TextRange.Text = file.Name ' <<< or whatever "title" you wanted
     End If
  Next

End Sub

您可以进一步修改它以获取所需格式的标题等。

于 2013-07-29T14:37:06.807 回答
2

你可以试试这个:

是否有使用 MATLAB 创建 PowerPoint 幻灯片的示例?

例如:

% before the following, you have to create the ppt as explained, see link above!
% I prefer using some name instead of i or j
for img_ind = 1:numel(pngfiles)
    % this depends on the ppt-version (see link above)-> here for 2007 and higher
    mySlide = Presentation.Slides.Add(1,'ppLayoutBlank')
    % Note: Change the image file full path names to where you save them
    Image1 = mySlide.Shapes.AddPicture('<full path>\name_of_image(img_ind).png','msoFalse','msoTrue',100,20,500,500)      
end
% then you have to save it, see link above!

在您的情况下,我想您必须先保存图像,如示例所示:

print('-dpng','-r150','<full path>\test1.png')

编辑

这仅在 Windows 上使用 Matlab 时有效,因为需要 COM。请参阅有关 Floris 答案的评论!

于 2013-07-29T12:51:11.013 回答
1

参加这个聚会迟到了:这是“本周的 Matlab 精选”工具:

http://www.mathworks.com/matlabcentral/fileexchange/30124-smart-powerpoint-exporter

请注意该页面上的一些评论,因为该工具显然在几年内没有更新。

于 2014-04-18T12:29:19.563 回答