How do I load an image file in Matlab? - matlab

I have to use Matlab to read a picture and make a joint histogram and I'm new to Matlab. When I try to read the Image by using imread function it does not work.
h= imread('a.tif');
??? Error using ==> imread at 363
File "a.tif" does not exist.
Can anyone help me figure out this problem?

One easy way to make sure you have the right path and file name is uigetfile.
To determine your path and filename, use
[filename,path]=uigetfile();
Then modify the code you have written to include the path as well. (If you're new to MATLAB, the syntax for combining two string arrays is [str1, str2])

Perhaps a.tif doesn't exist, or is located in the wrong directory ?
Since you didn't specify a path to the file then it needs to be in MATLAB's working directory (probably the same directory as where your .m file resides). Alternatively you can just specify a full (absolute) path to the .tif file.

Doesn't exist mean this image isn't supported by Matlab library
So, you should browse an image from your files but you must write URL FOR the Image like this :
a= (' D:\images\Angry Birds\bird.jpg');
imshow(a)

You need to load the picture first go to workspace then import data and select your file

Related

How to open .cs file using Matlab?

I am working on compressing an image using compressive sensing.
I downloaded the code. I ran the demo_firstTry.m, demo_GAPTV.m and demo_read_CSfile_and_Reconstruct.m functions, they worked well.
The problem is that I need the compressed vector, it is saved as .cs file in the path written on the function,
I don't know how to open this file to get the compressed image vector ?
You can use MATLAB's inbuilt function cv.imread as below:
img = cv.imread(filename)
img = cv.imread(filename, 'OptionName',optionValue, ...)
This should solve the query.

Exporting Matlab figure to .dxf using file exchange´s DXFLib

Problem
I am trying to export my matlab plot to a .dxf format. I am using this library DXFlib
I am using the following function of the library:
FID = dxf_polymesh(FID, VERTICES, FACES, varargin)
My plot is created of an alphashape:
h=plot(shp1,'FaceColor','red');
So I try to use the function by:
dxf_polymesh('test.dxf',h.Vertices,h.Faces)
Struct contents reference from a non-struct array object.
Error in dxf_polymesh (line 75) fclose(FID.fid);
In the test file of the library FID is described as follows:
FID is a structure containing handle to DXF file and parameters that
are used by remaining routines. DXFLib is a 'state' library.
Questions
This is probably a quite simple/stupid question:
What does FID in a content like this mean ( I know it stands for file identifier) but is this in this case the file I want to create, an existing file or something completly else ?
I guess I have some kind of wrong FID input from this error, what would be the right thing to enter in that function ?
Thanks for your help!

Saving data to file in different path in Matlab

I am trying to save some data from current workspace in Matlab to a different folder. I tried using
save('c:\stp\vtp\train.txt','data','-ASCII');
where data is a double matrix. It gives me error message
??? Error using ==> save
Unable to write file c:\stp\vtp\train.txt: No such file
or directory.
I tried using fullfile syntax, even then it is the same case. My current working folder is in different path.
You probably need to run mkdir first. For example:
%Some data to save
x = 1;
%Try to save it in a deep, non-existent directory
save(fullfile(tempdir,'sub1','sub2','sub3','sub4','data.mat'),'x');
% This will probably recreate your error
%To fix, first create the directory
mkdir(fullfile(tempdir,'sub1','sub2','sub3','sub4'))
%Now save works
save(fullfile(tempdir,'sub1','sub2','sub3','sub4','data.mat'),'x') %No error

Is there a function in MATLAB that converts a .raw file into a matrix?

I want to import a .raw file into MATLAB as a matrix (frames x spatial x spectral). Is there a built-in function to do this?
If you're referring to a raw image file from a camera, I would check out the submission RAW Camera File Reader from Bryan White on the MathWorks File Exchange.
You can also read the file directly. But you'll need to convert it to DNG first. See this:
http://blogs.mathworks.com/steve/2011/03/08/tips-for-reading-a-camera-raw-file-into-matlab/

display the output from mat file

Please, any one help me: how can I display the output (image file name, mean color image, color histogarm) to see it, which I saved it in sruct of array in mat file
You can load mat files (MatLAB) formats in the free software GNU Octave.
Loading it would give you a new variable, let's say a
After you loaded it, you can display it according to the structure using octave commands.
GNU octave can be downloaded here: http://www.gnu.org/software/octave/download.html
Example hist(a)