How to detect pixel matching conditions by the loop

4 次查看(过去 30 天)
Conducting visualization of the refrigerant and want to find out the quality of the flow with image processing.
Based on the visualized images, want to determine the quality of the refrigerant.
The purpose of the experiment is to make the evaporator pipe visible to understand how refrigerant flows in the pipe and how dryness occurs.
After adjusting the color level, we are going to figure out the boundary between pixels and find out the quality using the pixel ratio in the pipe.
but the problem is loop will be essential to detect the blue line, i cant just click every single pixel by myself.
here is the image which i have proceeded image processing.
and the red part if the flow which i want to figure out the quality by the image processing.
here is the boundary line got from the hough transformation.
And is ther any way to get the blue pixel's location by the loop?

回答(1 个)

Image Analyst
Image Analyst 2020-6-16
编辑:Image Analyst 2020-6-16
Try taking the average vertical profile of the edge image and then looking for peaks/spikes in the profile.
verticalProfile = sum(double(edgeImage), 2);
plot(verticalProfile, 'b-', 'LineWidth', 2);
grid on;
xlabel('Row', 'FontSize', 15);
ylabel('Count', 'FontSize', 15);
or you can try fitPolynomialRANSAC() if you have the Computer Vision toolbox.
If the camera is fixed, such that the red circled region is in the very same place for every image, then of course it would be much easier. Can you arrange that?
  3 个评论
Image Analyst
Image Analyst 2020-6-17
If the lines are horizontal, and you sum up the number of white pixels in each row of the image, explain to me why you don't think a high pixel count on the profile would indicate a horizontal line there. Explain why the code below does not find horizontal lines - why it will not "detect the blue line".
% Demo to find horizontal lines in edge image.
% By Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'refrig.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
% Crop off gray scale image and enormous white frame.
grayImage = grayImage(30:669, 447:806);
%--------------------------------------------------------------------------------------------------------
% SEGMENTATION OF IMAGE
% Get a binary image
binaryImage = imbinarize(grayImage);
subplot(2, 2, 2);
imshow(binaryImage, []);
impixelinfo;
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
verticalProfile = sum(double(binaryImage), 2);
subplot(2, 2, 3);
plot(verticalProfile, 'b-', 'LineWidth', 2);
grid on;
xlabel('Row', 'FontSize', 15);
ylabel('Count', 'FontSize', 15);
title('Vertical Profile', 'FontSize', 15);
% Find lines where there are more than 125 white pixels.
threshold = 125;
mask = verticalProfile < threshold;
verticalProfile(mask) = 0; % Erase outside of peak regions.
yline(threshold, 'Color', 'r', 'LineWidth', 3);
% Find peaks
[peakValues, peakRows] = findpeaks(verticalProfile);
% Draw red lines over those rows:
subplot(2, 2, 4);
imshow(binaryImage, []);
for k = 1 : length(peakRows)
yline(peakRows(k), 'Color', 'r', 'LineWidth', 3);
end
impixelinfo;
caption = sprintf('%d Horizontal Lines in Red', length(peakRows));
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
Seunghyuk Lee
Seunghyuk Lee 2020-6-17
I agree that these MATLAB CODE is awsome to find out the horizontal lines and able to find out the red line as you found. Here is image which will help you understand whats the problem i want to solve.
red box is the area which im interested. there is a boundary line with pipe and refrigerant flow
Using Hough transformation, got those blue line. pick those 4 points, two from the surface of refrigerant and two from the pipe. Want to know the pixel's location to know the distance ratio so that i can get refrigerant quality.
And finally, the loop is needed to make the quality more accurate by the average value.
So this is what i wanted to ask

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Biomedical Imaging 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by