Convert .MAT to .DAT in matlab for a 2D Image

5 views (last 30 days)
Hi,
I've been trying to convert .Mat files to .Dat file in MATLAB. Actually the codes takes .Dat file of an image and then denoises it.
I have .MAT MRI images and I'm unable to convert it into .DAT
Is there any way of changing the code if the first option isn't feasible?
Thanks for the response x
  4 Comments
Walter Roberson
Walter Roberson on 29 Jul 2015
What existing code is it that takes a .dat file extension?
Because .dat files can be anything, we need to know what format the existing code expects. In particular we need to know how the code expects the size information to be represented, and we need to know whether the code expects data to be stored "across" or "down" matrices, and we need to know how it wants the color planes to be interleaved if it supports color planes.
See also http://uk.mathworks.com/matlabcentral/answers/231355-how-to-create-a-dat-file-for-a-satellite-image in which someone thought they needed .dat but they do not.
Fakiha Akbar
Fakiha Akbar on 30 Jul 2015
Edited: Walter Roberson on 30 Jul 2015
load 'lena_clean.dat';
setup_path;
% stats.errs = cell(2,1);
% stats.Fx = cell(2,1);
% read data, assume size 512x512
fprintf('Reading image: %s\n', dataset );
image_noisy_file = [dataset,'.dat'];
image_clean_file = [dataset,'_clean.dat'];
image_sol_file = [dataset,'_sol',num2str(model),'.dat'];
img = load(image_clean_file, '-ascii');
noisyImg = load(image_noisy_file, '-ascii');
if exist(image_sol_file, 'file')==2
ref_sol = load(image_sol_file, '-ascii');
else
ref_sol = load(image_noisy_file, '-ascii');
end
This is the part of the code which takes .dat 2D images, 512x512 is the size. It doesn't support color planes.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Jul 2015
matname = [dataset '.mat'];
datastruct = load(matname);
fn = fieldnames(datastruct);
outname = [dataset '.dat'];
data_to_save = datastruct.(fn{1});
save(outname, 'data_to_save', '-ASCII');

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!