Sie sind auf Seite 1von 5

function [X,d] = readis2(f,map) %READIS2 Import data files from Fluke infrared thermal camera (IS2 format).

% X=READIS2(FILENAME) reads IS2 radiometric file FILENAME and % returns a structure X containing fields with data and headers: % IR: infrared sensor values (240x320 uint16 matrix) % TB: brillancy temperatures, in C (240x320 double matrix) % T: body temperatures, in C (240x320 double matrix) % VI: visible image (480x640x3 uint8 RGB) % VI2: cropped and interpolated visible image adjusted on IR % image pixels (240x320x3 uint8 RGB) % Emissivity: emissivity value (0 to 1.00) % Transmission: transmission value (0 to 1.00) % BackgroundTemp: background temperature (C) % Date: [YEAR MONTH DAY HOUR MINUTE SECOND] % % X=READIS2(FILENAME,MAP) plots temperature image using MAP color scale % over visible image. MAP is a valid [n x 3] RGB colormap, for instance % JET or GRAY. READIS2(...) without output argument makes also a plot. % % Notes: % - the function has been tested only with original IS2 files from a % Fluke TI32 camera. % - to produce temperatures from IR sensor values, the function needs a % calibration file 'readis2_ti32.dat' located in current directory or % Matlab path. % - body temperatures Tr (output X.T) and brillancy temperatures Tb % (output X.IR) are related with the formula: % Tb = e*t*Tr + (1-e)*(1-t)*Te % where e is emissivity, t is transmission, and Te is background % (reflected) temperature. So Tb and Tr are equal for e = t = 1. % % Author: Franois Beauducel <beauducel@ipgp.fr> % Institut de Physique du Globe de Paris % % Created: 2011-07-24 % Updated: 2011-09-12 % % Acknowledgments: % Magnus Andersen (read_is2.m), Pierre Agrinier, Valrie Clouard % % % % % % % % % % % % tion % % IS" % E % SE Copyright (c) 2011, Franois Beauducel, covered by BSD License. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribu THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO

% % % % % % % HE %

ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF T POSSIBILITY OF SUCH DAMAGE.

error(nargchk(0,2,nargin)) unit = 'count'; makeplot = 0; if nargin < 1 [filename,pathname] = uigetfile('*.IS2','Please select a file...'); f = fullfile(pathname,filename); end if ~ischar(f) ~exist(f,'file') error('File %s does not exist.',f); end if nargin == 2 if ~isnumeric(map) size(map,2) ~= 3 error('MAP must be a colormap Mx3 matrix'); end makeplot = 1; else map = jet(2^16); end % Temperature calibration file fcal = 'readis2_ti32.dat'; % ATTENTION: this file must exist in the Matlab path to produce temperature % values in C (otherwise temperatures are given in counts). % The data come from interpolation of sample images exported using the % Fluke SmartView software if exist(fcal,'file') tcal = load(fcal); unit = 'C'; else warning('Calibration file "%s" not found.\nOutput IR temperatures will b e uncalibrated (uint16).',fcal); end % data offsets offset_ir = 7989; offset_vi = 84817; % --- reads the whole file in uint16 fid = fopen(f); d = fread(fid,'*uint16'); fclose(fid); % --- gets some header informations

% header index = d(1:7989) and d(84790:84817) header{1} header{2} header{3} header{4} header{5} = = = = = char(d(88:105))'; % CameraManufacturer char(d(120:130))'; % CameraModel char(d(152:170))'; % CameraSerial char(d(184:198))'; % EngineSerial fliplr(typecast(d(64:65),'uint8')');

% FirmwareVersion

% get the date and time daymonth = double(typecast(d(2936)','uint8')); % day and month year = double(d(2937)); % year msec = double(typecast(d(2934:2935),'uint32')); % number of milliseconds in the day dte = datenum(year,daymonth(2),daymonth(1),0,0,msec/1000); % get IR parameters emissivity = double(typecast(d(2940:2941),'single')); transmission = double(typecast(d(2942:2943),'single')); backgroundtemp = double(typecast(d(2944:2945),'single')); % IR image size irsz(1) = double(typecast(d(7984:7985),'uint32')); irsz(2) = double(typecast(d(7986:7987),'uint32')); % visible image size visz(1) = double(typecast(d(2930:2931),'uint32')); visz(2) = double(typecast(d(2932:2933),'uint32')); vsz = [visz(2),visz(1),3]; % [480,640,3] % 320 % 240 % 640 % 480

% --- reads IR image (320x240 16-bit) ir = reshape(d(offset_ir+(1:prod(irsz))),irsz)'; if exist('tcal','var') tb = interp1(tcal(:,1),tcal(:,2),double(ir),'linear','extrap'); else tb = double(ir); end % --- computes body temperature from brillancy temperature and parameters t = tb/(emissivity*transmission) - (1-emissivity)*(1-transmission)*backgroundtem p; tlim = minmax(t); tavr = mean(mean(t)); % --- reads visible image (640x480 16-bit RGB coded 5:6:5) v = reshape(d(offset_vi+(1:prod(vsz(1:2)))),vsz(2),vsz(1))'; vi = zeros(vsz,'uint8'); vi(:,:,3) = bitshift(bitand(v,31),3); % 5 less signifi cant bits = blue vi(:,:,2) = bitshift(bitand(bitshift(v,-5),63),2); % 6 middle bits = green vi(:,:,1) = bitshift(bitshift(v,-11),3); % 5 most signifi cant bits = red % incrustes IR image into visible one (IR-Fusion simulation) x0 = 1:irsz(1); y0 = 1:irsz(2); r = 1.25; [xx,yy] = meshgrid(linspace(x0(1),x0(end),length(x0)*r),linspace(y0(1),y0(end),l ength(y0)*r)); ti = interp2(x0,y0,double(t),xx,yy,'*linear');

s2 = size(ti); ti = ind2rgb(floor((size(map,1)-1)*(ti-min(min(ti)))/diff(minmax(ti))+1),map); ii = (vsz(1)-s2(1))/2 + (1:s2(1)); jj = (vsz(2)-s2(2))/2 + (1:s2(2)); blend = vi; blend(ii,jj,:) = uint8(256*ti); % crops and interpolates visible image to fit IR image x1 = 1:length(jj); y1 = 1:length(ii); [xx,yy] = meshgrid(linspace(1,length(jj),irsz(1)),linspace(1,length(ii),irsz(2)) ); vi2(:,:,1) = uint8(interp2(x1,y1,double(vi(ii,jj,1)),xx,yy,'*linear')); vi2(:,:,2) = uint8(interp2(x1,y1,double(vi(ii,jj,2)),xx,yy,'*linear')); vi2(:,:,3) = uint8(interp2(x1,y1,double(vi(ii,jj,3)),xx,yy,'*linear')); if nargout X.Filename = f; X.VI = vi; X.VI2 = vi2; X.IR = ir; X.TB = tb; X.T = t; X.Unit = unit; X.Range = tlim; X.IRBlend = blend; X.Date = datevec(dte); X.Emissivity = emissivity; X.Transmission = transmission; X.BackgroundTemp = backgroundtemp; X.CameraManufacturer = header{1}; X.CameraModel = header{2}; X.CameraSerial = header{3}; X.EngineSerial = header{4}; X.IRSensorSize = irsz; X.Firmware = sprintf('%d.%d.%d.%d',header{5}); else makeplot = 1; end if makeplot figure, orient tall subplot(3,1,1:2) imagesc(blend) title({sprintf('%s %s',header{1},header{3}), ... sprintf('"%s" [%s]',f,datestr(dte))}, ... 'FontSize',10,'FontWeight','bold','Interpreter','none') axis image, axis off h = colorbar; title(h,unit) colormap(map) caxis(tlim) subplot(3,1,3) bins = linspace(tlim(1),tlim(2),100); ht = 100*histc(t(:),bins)/numel(t); h = bar(bins,ht); set(get(h,'Children'),'CData',bins); % makes indexed color bars set(gca,'XLim',tlim) xlabel(sprintf('IR Temperature (%s)',unit))

ylabel('Pixels (%)') title({sprintf('Emissivity = %g / Transmission = %g / Background Temp. = %g C', ... emissivity, transmission, backgroundtemp), ... sprintf('Temperature Avr. = %+1.2f %s / Min. = %+1.2f %s / Max. = %+1.2f %s', ... tavr,unit,tlim(1),unit,tlim(2),unit)}, ... 'FontSize',10) end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function y = minmax(x) % minmax(X) returns [MIN,MAX] vector with min and max values of matrix X y = [min(min(x)),max(max(x))];

Das könnte Ihnen auch gefallen