How to know pixel size ?

5 visualizaciones (últimos 30 días)
Amine Alileche
Amine Alileche el 4 de Mayo de 2021
Comentada: Amine Alileche el 6 de Mayo de 2021
Hello,
I have two types of files "csv" and "jpg". I want to extract temperature along the wire shown in the picture ( I took maximum value of each line of the csv file ) . So I need to detect boundaries of the wire at and plot temperature along the real length of the wire knowing that I know one dimension in the picture.

Respuestas (2)

Walter Roberson
Walter Roberson el 4 de Mayo de 2021
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/607160/125-1.csv');
imagesc(data)
th = data > 25;
h_th = any(th,1);
h_lb = find(h_th,1);
h_ub = find(h_th,1,'last');
hold on
xline(h_lb, 'r')
xline(h_ub, 'r');
hold off
However, in order to know the pixel size, you need a fixed distance. In your .jpg you manually drew on a distance, but it is not clear where you got that distance from? If you know the physical distance that the full number of columns corresponds to, then
width_of_full_image = 11.3; %change as appropriate!
units_per_pixel = width_of_full_image / size(data,2);
width_of_selected_area = (h_ub - h_lb + 1) * units_per_pixel
width_of_selected_area = 1.2889
  4 comentarios
Walter Roberson
Walter Roberson el 5 de Mayo de 2021
You drew a box around the wire. How did you decide where the boundaries of that box should be?
Amine Alileche
Amine Alileche el 5 de Mayo de 2021
No it's an infra red picture and I know the width of the lgbt. so I know that real distance

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 4 de Mayo de 2021
After you get your data, use max():
% Demo by Image Analyst.
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 18;
markerSize = 20;
% Read in file.
fileName = '125-1.csv';
data = readmatrix(fileName);
[rows, columns] = size(data);
nexttile;
imshow(data, []);
axis('on', 'image');
% Scan rows for max in each column.
minValue = min(data(:));
maxProfile = minValue * ones(rows, 1);
colOfMax = ones(rows, 1);
for row = 1 : rows
[maxProfile(row), colOfMax(row)] = max(data(row, :));
end
% Plot red line over image.
hold on;
plot(colOfMax, 1:rows, 'r-', 'LineWidth', 2);
% Plot intensity along row.
nexttile;
plot(maxProfile, 'b-', 'LineWidth', 2);
grid on;
xlabel('row', 'FontSize', fontSize);
ylabel('Intensity', 'FontSize', fontSize);
% Maximize image.
g = gcf;
g.WindowState = 'maximized'
Note: the graph is the vertical profile along the centerline of the wire (going down row by row).
It is not a cross section of the wire horizontally.
  3 comentarios
Image Analyst
Image Analyst el 5 de Mayo de 2021
If you want to find the starting and ending row of the largest stretch above a threshold, you can use find() and bwareafilt()
[rows, columns] = size(data);
startingColumns = zeros(rows, 1);
endingColumns = zeros(rows, 1);
threshold = 26; % Whatever.
for row = 1 : rows
thisRow = data(row, :) > threshold; % Binary "image"
% Extract the longest run, in case there are more than one due to noise
thisRow = bwareafilt(thisRow, 1);
col = find(thisRow, 1, 'first');
if ~isempty(col)
startingColumns(row) = col; % Store starting column.
endingColumns(row) = find(thisRow, 1, 'last'); % Store ending column.
end
end
Amine Alileche
Amine Alileche el 6 de Mayo de 2021
So should I put then plot(startingColumns-endingColumns,maxProfile, 'b-', 'LineWidth', 2);

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by