Matlab - Crear un LanAdapter para abrir imágenes en formato LAN

 
Vista:

Crear un LanAdapter para abrir imágenes en formato LAN

Publicado por klipya (13 intervenciones) el 06/02/2013 14:31:57
Hola,

Estoy intentando de abrir imágenees LAN y he estado mirando la ayuda de Matlab. he encontrado este código y estoy intentando de probarlo pero no me funciona.

Primero de todo, abro el encabezado.

file_name = 'rio.lan';
fid = fopen(file_name,'r');
header_str = fread(fid,6,'uint8=>char')';
fprintf('Header String: %s\n',header_str);

% Leer el tipo de imagen, el número de bandas y el tamaño
pack_type = fread(fid,1,'uint16',0,'ieee-le');
fprintf('Pack Type: %d\n',pack_type); num_bands = fread(fid,1,'uint16',0,'ieee-le');
fprintf('Number of Bands: %d\n',num_bands); unused_bytes = fread(fid,6,'uint8',0,'ieee-le');
width = fread(fid,1,'uint32',0,'ieee-le');
height = fread(fid,1,'uint32',0,'ieee-le');
fprintf('Image Size (w x h): %d x %d\n',width,height);Then, it's supposed that I have to create the LanAdapter.

Puedo escribir esto en Matlab? Recibo el siguiente error : Function definitions are not permitted in this context." pero lo estoy haciendo en un script de función.


classdef LanAdapter < ImageAdapter
properties(GetAccess = public, SetAccess = private)
Filename
NumBands
end properties(Access = public)
SelectedBands
end

La siguiente parte es esta. Necestio cambiar parámetros?

methods function obj = LanAdapter(fname)
% LanAdapter constructor for LanAdapter class.
% When creating a new LanAdapter object, read the file
% header to validate the file as well as save some image
% properties for later use. % Open the file.
obj.Filename = fname;
fid = fopen(fname,'r'); % Verify that the file begins with the string 'HEADER' or
% 'HEAD74', as per the Erdas LAN file specification.
header_str = fread(fid,6,'uint8=>char');
if ~(strcmp(header_str','HEADER') || strcmp(header_str',...
'HEAD74'))
error('Invalid LAN file header.');
end % Read the data type from the header.
pack_type = fread(fid,1,'uint16',0,'ieee-le');
if ~isequal(pack_type,0)
error('Unsupported pack type. The LanAdapter example only...
supports reading uint8 data.');
end % Provide band information.
obj.NumBands = fread(fid,1,'uint16',0,'ieee-le');
% By default, return all bands of data
obj.SelectedBands = 1:obj.NumBands; % Specify image width and height.
unused_field = fread(fid,6,'uint8',0,'ieee-le'); %#ok<NASGU>
width = fread(fid,1,'uint32',0,'ieee-le');
height = fread(fid,1,'uint32',0,'ieee-le');
obj.ImageSize = [height width]; % Close the file handle
fclose(fid); end % LanAdapter


Otra parte...


function data = readRegion(obj, region_start, region_size)
% readRegion reads a rectangular block of data from the file. % Prepare various arguments to MULTIBANDREAD.
header_size = 128;
rows = region_start(1):(region_start(1) + region_size(1) - 1);
cols = region_start(2):(region_start(2) + region_size(2) - 1); % Call MULTIBANDREAD to get data.
full_size = [obj.ImageSize obj.NumBands];
data = multibandread(obj.Filename, full_size,...
'uint8=>uint8', header_size, 'bil', 'ieee-le',...
{'Row', 'Direct', rows},...
{'Column','Direct', cols},...
{'Band', 'Direct', obj.SelectedBands}); end % readRegionThe last one...

function close(obj) %#ok<MANU>
% Close the LanAdapter object. This method is a part
% of the ImageAdapter interface and is required.
% Since the readRegion method is "atomic", there are
% no open file handles to close, so this method is empty. end end % public methods end % LanAdapter


El problema es que no sé como cambiarlo y ejecutarlo, si tiene una cierta relación.

Gracias de antemano y saludos,
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder