Non-rectangular thermal image crop & matching
이전 댓글 표시
How to create rectangular IR image and contour with a false color map from the measured non-rectangular image and data from an Excel sheet?
I want to transform the results of the IR image and temperature data from the Excel sheet into a rectangular format. The interrogation region from the measuring devices is non-rectangular. Procedures are attached in the PDF file. I need help matching rectangularized IR images having the original color map with Excel data.
채택된 답변
추가 답변 (1개)
Garmit Pant
2024년 3월 5일
Hello bk park
From what I gather, you are trying to read data from a CSV file and then converting the non-rectangular interrogation region of the temperature measured to a rectangular shape.
This can be achieved by reading the data and first preprocessing it into a usable form. Further, you’d need to isolate the non-rectangular interrogation region using some threshold. Then, the non-rectangular region can be changed to a rectangular shape using padding with 0’s. Another method can be data interpolation. The following code snippet shows how to extract usable data, then the interrogation region and then a rectangular region using both padding and interpolation.
% Read the table from a CSV file
tbl = readtable("good-vip10t,single=IMG_20231219_214630_TEMP_01title.csv");
% Initialize an empty array to store processed temperature data
b = [];
% Loop through each row of the 'Tempeature_IR' column in the table
for i = 1:size(tbl.Tempeature_IR,1)
% Extract the temperature string for the current row, removing quotes
a1 = tbl.Tempeature_IR{i};
a1 = a1(a1~='"');
% Split the string into individual temperature values
a1 = strsplit(a1);
% Convert the temperature strings to numeric values
a1 = str2double(a1);
% Append the numeric temperature values to the array 'b'
b = [b; a1];
end
% Remove the last column from 'b'
b = b(:,1:end-1);
% EXTRACTING INTERROGATION REGION USING THRESHOLDING
% Filter columns of 'b' to keep only those where the first row value is >=
% 40. You can change the threshold.
colsToKeep = b(1, :) >= 40;
result1 = b(:, colsToKeep);
% Initialize the size of the 'result1' matrix
[rows, cols] = size(result1);
% Iterate through each row of 'result1'
for i = 1:rows
% Find the last index in the row where the value is >= 38
idx = find(result1(i, :) >= 38, 1, 'last');
% If such an index is found, set all subsequent elements in the row to 0
if ~isempty(idx)
result1(i, idx+1:end) = 0;
end
end
% PADDING THE OUTSIDE REGION WITH 0's
% Create a mask for values in 'result1' that are >= 38
mask = result1>=38;
% Initialize 'maskedresult' as a copy of 'result1'
maskedresult = result1;
% Set all values in 'maskedresult' that meet the mask condition to 0
maskedresult(mask)=0;
% INTERPOLATION
% Create a meshgrid for the coordinates of 'maskedresult'
[x, y] = meshgrid(1:size(maskedresult,2), 1:size(maskedresult,1));
% Identify indices of zero and non-zero values in 'maskedresult'
zeroInd = find(maskedresult == 0);
nonZeroInd = find(maskedresult ~= 0);
% Extract coordinates and values for interpolation
xq = x(zeroInd); % x-coordinates of zeros
yq = y(zeroInd); % y-coordinates of zeros
xv = x(nonZeroInd); % x-coordinates of non-zeros
yv = y(nonZeroInd); % y-coordinates of non-zeros
v = maskedresult(nonZeroInd); % non-zero values
% Use 'scatteredInterpolant' for interpolation with linear interpolation
% and nearest extrapolation for out-of-bound points
F = scatteredInterpolant(xv, yv, v, 'linear', 'nearest');
% Interpolate values for positions that were zero in 'maskedresult'
interpolatedValues = F(xq, yq);
% Replace zero values in 'maskedresult' with the interpolated values
maskedresult(zeroInd) = interpolatedValues;
% Display the matrix after interpolation
disp('Matrix after interpolation:');
disp(maskedresult);
The above operation give the following heatmaps:
Picture 1: Padded with 0’s

Picture 2: Interpolated.
For further understanding, refer to the links to the MATLAB documentation given below:
- “scatteredInterpolant ” function- https://www.mathworks.com/help/releases/R2022b/matlab/ref/scatteredinterpolant.html
I hope you find the above explanation and suggestions useful!
카테고리
도움말 센터 및 File Exchange에서 White에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



