matlabfileimread

How to add unique image formats to Matlab's imread, and Matlab's drag and drop?


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.)


Solution

  • 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. :)