필터 지우기
필터 지우기

Using image processing tool measure the angle

조회 수: 23 (최근 30일)
Akbar
Akbar 2014년 5월 7일
댓글: Darya Yakovleva 2021년 4월 21일
UsingMATLAB image processingtool, measure the angle between the connections for the following figures.
Teacher said that after some image processing we will need the polyfit function to determine the angle. And it will be good if our program calculates average angle rather than for only one incline.
  댓글 수: 3
Akbar
Akbar 2014년 5월 25일
Below i've provided a code that i wrote for the image below. Now when you type:
imshow(D)
you will see two "lines" almost parallel to each other. I need help in finding their slopes (angles).
% Rope.m
% measure the angle between the connections
clc; clear; figure
A = imread('Rope.jpg');
B = rgb2gray(A);
C = imcrop(B, [220 295 70 90]);
D = C > 60;
%E=B>60;
%F = imcrop(E, [10 10 480 480]);
subplot(2,2,1); imshow(A);
subplot(2,2,2); imshow(B);
subplot(2,2,3); imshow(C);
subplot(2,2,4); imshow(D);
Akbar
Akbar 2014년 5월 25일
I think i should transform black pixels in image "D" to data points in x-y plane, then "somehow" using curve fitting find the slope or angle???

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2018년 1월 20일
Try this:
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 = 20;
% Check that user has the specified Toolbox installed and licensed.
hasLicenseForToolbox = license('test', 'image_toolbox'); % license('test','Statistics_toolbox'), license('test','Signal_toolbox')
if ~hasLicenseForToolbox
% User does not have the toolbox installed, or if it is, there is no available license for it.
% For example, there is a pool of 10 licenses and all 10 have been checked out by other people already.
ver % List what toolboxes the user has licenses available for.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in gray scale demo image.
folder = pwd; % Determine where demo folder is (works with all versions).
baseFileName = 'rope.jpg';
% 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
rgbImage = imread(fullFileName);
% Display the image.
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
hp = impixelinfo();
% 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(rgbImage);
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(rgbImage);
% 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 = rgbImage(:, :, 3); % Take bluechannel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
subplot(2, 2, 2);
histogram(grayImage);
grid on;
title('Histogram', 'FontSize', fontSize, 'Interpreter', 'None');
% Create an edge image.
edgeImage = imgradient(grayImage);
% Get rid of upper rope.
edgeImage(1:300, :) = 0;
% Display the image.
subplot(2, 2, 3);
imshow(edgeImage, []);
title('Edge Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
hp = impixelinfo();
% Display the histogram.
subplot(2, 2, 4);
histogram(edgeImage);
grid on;
title('Histogram of Edge Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Get rid of bright outer edges.
binaryImage = edgeImage > 1;
figure;
% Display the image.
subplot(2, 2, 1);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Fill holes
binaryImage = imfill(binaryImage, 'holes');
% Do an opening to separate the blobs.
se = strel('disk', 15, 0);
binaryImage = imerode(binaryImage, se);
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Mask the original edge image
edgeImage(~binaryImage) = 0;
% Display the image.
subplot(2, 2, 3);
imshow(edgeImage, []);
title('Edge Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Display the histogram.
subplot(2, 2, 4);
histogram(edgeImage);
grid on;
title('Histogram of Edge Image', 'FontSize', fontSize, 'Interpreter', 'None');
% [lowThreshold, highThreshold, lastThresholdedBand] = threshold(20, 255, edgeImage);
lowThreshold = 100;
% Take the 24 largest blobs.
binaryImage = edgeImage > lowThreshold;
% Get rid of blobs smaller than 50 pixels.
binaryImage = bwareafilt(binaryImage, [50, inf]);
figure;
% Display the image.
subplot(2, 2, 1);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
% Get the orientations (angles
props = regionprops(binaryImage, 'Orientation', 'Area');
allAreas = [props.Area]
allAngles = [props.Orientation]
% Throw out unreasonable angles, like those less than 10 degrees.
allAngles(allAngles < 10) = [];
% Display the histogram.
subplot(2, 2, 2);
histogram(allAngles);
grid on;
title('Histogram of Edge Angles', 'FontSize', fontSize, 'Interpreter', 'None');
% Compute the mean angle
meanAngle = mean(allAngles)
message = sprintf('The mean angle = %f', meanAngle);
helpdlg(message);
  댓글 수: 4
Troels Ditlev Nicolajsen
Troels Ditlev Nicolajsen 2019년 4월 8일
Thanks
- Ditlev
Darya Yakovleva
Darya Yakovleva 2021년 4월 21일
Hello! Could you tell me please, how to measure the avarege width of the rope?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Van S
Van S 2018년 1월 20일
Dear Akbar,
I am interesting in angle measurement of the rope in matlab, could you please share to me about that now.
I really appreciate of your help. Best regards; Sry

VIJI S
VIJI S 2019년 8월 8일
I want to know the angle measurement in face image one is template(that is detected face)and other one is set of database which have different pose in face please help me please

VIJI S
VIJI S 2019년 8월 8일
I want to find the mean angle of face
  댓글 수: 1
Image Analyst
Image Analyst 2019년 8월 9일
Why?
Anyway, use polyfit() to fit a line across the top of the rope and bottom of the rope, then along each twist. Then average the sets of lines and take the difference in angles. Sorry, I don't have code for that but polyfit() is super easy to use - I'm sure you can do it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by