Infrared Thermography Image Analysis Code Error
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi wondering if anyone can help me?
I have infrared images (saved as dat. files) which I am trying to analyse using MATLAB. From the images I need to be able to determine a number of things:
1) The maximum temperature within the image
2) The temperature of a manually selected point within the image
3) Based on the manually selected point I then need to be able to be able to trace a box of both 3x3 and 9x9 pixel dimensions to tell me the maximum temperature within the traced box.
I'm new to using MATLAB but have been sent some code (below) to run that should be able to help me get the information as mentioned above from the images. Currently the code loads the images and automatically indicates the maximum temperature of the image with a red marker (As shown in example "Matlab IMGa" attached). I then left click within the image to determine the maximum temperature of a selected point within the image which is then indicated with a blue marker. Based on this selected point the code then automatically traces a green box based on the coordinates of the selected point within the image (the dimensions of which be adjusted in the code) (As shown in example "Matlab IMGb" attached). After which the next image for analysis should automatically be loaded. However I keep getting the following error after selecting the point within the image.
Warning: Integer operands are required for colon operator when used as index.
> In Calf_Code_Gemma (line 122)
Warning: Integer operands are required for colon operator when used as index.
> In Calf_Code_Gemma (line 122)
Index in position 2 is invalid. Array indices must be positive integers or logical values.
Error in Calf_Code_Gemma (line 123)
maxp(end + 1, :) = {x,int8(y),img(int8(y),x),'Selected', cx, cy, size(temp,1), size(temp, 2), max(max(temp)),
min(min(temp)), mean(mean(temp))};
Can anyone explain to me what is causing this error and how the code might be adjusted to overcome the error?
Any advice would be much appreciated!! :)
Cheers,
Gemma

% Script to load .dat files
clc; clear; clf; fclose('all'); tic;
% This is
selpath = uigetdir(path,'Select images folder to open');
% find all the files within the directory
temp = dir(selpath);
% Filter out anyting that is not a file and less than 300KB in size
disp('Filtering image file');
i=1;
files = temp(1);
for i = 1 : size(temp,1)
% disp(sprintf('File Name: %s\nFile size: %d\nIndex :%d', temp(i).name, temp(i).bytes, i));
if ((~temp(i).isdir) && (temp(i).bytes > 307000))
files(end + 1) = temp(i);
% disp('keep');
end
end
files(1) = [];
disp('Finished filtering');
clearvars -except selpath files
% Work out file info
lim = size(files, 2);
data = {'ID', 'EID', 'Date', 'Trigger Time', 'Image Time', 'Image Number', 'Bail Number', 'Fram', 'x' , 'y', 'Temperature', 'Temp Type', 'Cheek x', 'Cheek Y', 'Width', 'height', 'Max', 'Min', 'Mean' };
for i=1:size(files, 2)
name = files(i).name;
ind = strfind(name, ',');
if size(ind,2) == 6
% file name format: date, trigger time, farm name, bail ID, Image time,
% Image number, EID
info(1) = {name(1: ind(1) - 1)};
info(2) = {name(ind(1) + 1: ind(2) - 1)};
info(3) = {name(ind(2) + 1: ind(3) - 1)};
info(4) = {name(ind(3) + 1: ind(4) - 1)};
info(5) = {name(ind(4) + 1: ind(5) - 1)};
info(6) = {name(ind(5) + 1: ind(6) - 1)};
info(7) = {name(ind(6) + 1: end)};
info(4) = {strrep(info{4}, 'B', '')};
info(6) = {strrep(info{6}, 'IMG_', '')};
info(7) = {strrep(info{7}, '.dat', '')};
str = sprintf('Image : %d of %d\nEID : %s\nDate : %s\nIMG time : %s\nIMG No. : %s', i, lim, info{7}, info{1}, info{5}, info{6});
disp(str);
disp('----------------------');
name = strcat(selpath, '\', name);
% Open the open and copy out the pixel informartion
fileOpen = fopen(name,'r');
temp = (fread(fileOpen,inf,'single'));
fclose(fileOpen);
% If the is loaded correctly reshape it
img = reshape(temp, 320, 240)';
%convert Kelvin temperatures to Celcius
img = img - 273.15;
% Max tempature of image
maxt = max(max(img));
maxp = {};
%find all the pixels at maxi temp
for r = 1:240
for c = 1:320
if img(r,c) == maxt
maxp(end + 1, :) = {c,r,maxt,'Max', '', '', '', '', '', '', '',}; %x,y
end
end
end
% Format the image
imshow(mat2gray(img));
hold on;
plot(maxp{:,1}, maxp{:, 2}, 'rd');
hold on;
legend('Max Temp', 'Location','SouthEast');
hold on;
%Select a dat point
[x,y,b] = ginput(1);
%left click to skip image
if b == 1
plot(x, y, 'bd');
hold on;
% cheek region
width = 50;
height = 30;
offsetY = 25; %+ve down
offsetX = -10; %+ve right
cx = x+offsetX;
cy = y+offsetY;
cyLim = cy+height-1;
cxLim = cx+width-1;
hold on
plot(cx, cy, 'md');
hold on
if cyLim > 240
cyLim = 240;
disp('Cheek y limit exceeds image size, y set to 240');
end
if cxLim > 320
cxLim = 320;
disp('Cheek x limit exceeds image size, x set to 320');
end
rectangle('Position', [cx, cy, (cxLim-cx), (cyLim-cy)], 'EdgeColor', 'g');
hold on;
legend('Max Temp', 'Selected Point', 'Location','SouthEast');
temp = img(cy:cyLim, cx:cxLim);
maxp(end + 1, :) = {x,int8(y),img(int8(y),x),'Selected', cx, cy, size(temp,1), size(temp, 2), max(max(temp)), min(min(temp)), mean(mean(temp))};
%If data selected add the data to the array
for t=1:size(maxp,1)
data(end + 1, :) = {'', info{7}, info{1}, info{5}, info{2}, info{6}, info{4}, info{3}, maxp{t,1}, maxp{t,2}, maxp{t,3}, maxp{t,4}, maxp{t,5}, maxp{t,6}, maxp{t,7}, maxp{t,8}, maxp{t,9}, maxp{t,10}, maxp{t,11}};
end
pause();
end
fclose('all');
clf;
clearvars -except selpath files i lim data
end
end
clearvars -except selpath data
saveData(selpath, data);
toc
0 commentaires
Réponses (1)
Guillaume
le 25 Sep 2019
The mouse coordinates returned by ginput are rarely integers so, indeed, you can't use them as is as image pixel coordinates. The easiest way to fix this is to round the coordinates to the nearest integer (and check that the points are within the image). So, after
[x,y,b] = ginput(1);
add
x = round(x);
y = round(y);
assert(x > 0 && y > 0 && x <= size(img, 2) && y <= size(img, 1) && isscalar(x), 'Selected point outside the image or multiple points specified');
Also, replace the int8(y) by just y. It looks like it was an attempt by the original author to round the y coordinate (but why not x). However, that would only work properly for images whose height is less than 256 pixels.
1 commentaire
Guillaume
le 25 Sep 2019
Gemma Lowe's comment mistakenly posted as an answer moved here:
Many thanks for your response! I will give that a go, hopefully it does the trick. :)
Voir également
Catégories
En savoir plus sur Vehicle Scenarios dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!