如何为Matlab的图像和Matlab的拖放内容添加独特的图像格式? [英] How to add unique image formats to Matlab's imread, and Matlab's drag and drop?

查看:97
本文介绍了如何为Matlab的图像和Matlab的拖放内容添加独特的图像格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Matlab中处理了许多内部图像格式.我对所有这些都有读/写功能.具体而言,请考虑 TGA 图片格式,该格式需要文件交换 imread .

也就是说,您可以从资源管理器中拖动图像,将其拖放到工作区"窗格中,Matlab将读取该图像,并将其复制到您的工作区中.

我希望能够添加拖放支持,并扩展对TGA文件的支持. (例如,imread对文件名具有很好的自动完成功能,而tga_read_image则没有.)

解决方案

Tommaso的答案开始,我创建了在我的MATLAB路径上跟随以下M文件:

function out = openics(filename)
img = readim(filename);
if nargout==1
   out = img;
else
   [~,varname] = fileparts(filename);
   disp(['assigning into base: ',varname])
   assignin('base',varname,img);
end

将ICS文件拖放到MATLAB的命令窗口上,在命令行上显示以下内容:

>> uiopen('/Users/cris/newdip/examples/cermet.ics',1)
assigning into base: cermet

检查:

>> whos cermet
  Name          Size             Bytes  Class        Attributes
  cermet      256x256            65714  dip_image              

读取uiopen的代码(您可以键入edit uiopen)表明,此操作使用文件名调用open,然后使用文件名且没有输出参数调用openics.

您也可以输入

img = open('/Users/cris/newdip/examples/cermet.ics');

调用openics并将图像加载到变量img.

注1:我正在使用ICS,因为我没有要测试的TGA图像. ICS是显微镜图像文件格式.

注2:readim DIPimage

注3:太酷了,我之前从未尝试过将文件拖放到MATLAB上. :)

We have a number of internal image formats which I process in Matlab. I have read/write functions for all of them. For specificity, consider the TGA image format, for which there is a file exchange image reader.

Matlab has reasonable drag and drop support for image formats supported by imread.

That is, you can drag an image from explorer, drop it on the "Workspace" pane, and Matlab will read in the image, and copy it into your workspace.

I'd like to be able to add drag and drop support, and imread support for TGA files. (imread has nice autocomplete for filenames for instance, tga_read_image does not.)

解决方案

Starting off from Tommaso's answer, I created the following M-file on my MATLAB path:

function out = openics(filename)
img = readim(filename);
if nargout==1
   out = img;
else
   [~,varname] = fileparts(filename);
   disp(['assigning into base: ',varname])
   assignin('base',varname,img);
end

Dragging and dropping an ICS file onto MATLAB's command window shows the following on the command line:

>> uiopen('/Users/cris/newdip/examples/cermet.ics',1)
assigning into base: cermet

Check:

>> whos cermet
  Name          Size             Bytes  Class        Attributes
  cermet      256x256            65714  dip_image              

Reading the code for uiopen (you can just type edit uiopen) shows that this calls open with the filename, which then calls openics with the filename and no output argument.

You can also type

img = open('/Users/cris/newdip/examples/cermet.ics');

to call openics and load the image into variable img.

NOTE 1: I'm using ICS because I don't have any TGA images to test with. ICS is a microscopy image file format.

NOTE 2: readim is a function in DIPimage

NOTE 3: This is cool, I had never bothered trying to drag and drop files onto MATLAB before. :)

这篇关于如何为Matlab的图像和Matlab的拖放内容添加独特的图像格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆