Error: Expected input to be a vector

조회 수: 43(최근 30일)
Teshan Rezel
Teshan Rezel 2021년 6월 10일
댓글: Max Heiken 2021년 6월 10일
Hi folks,
I am calling a self-made function as follows:
ir = rotateAround(ig, Cy, Cx, Angle_DEG);
But the last variable, Angle_DEG, has no value so I get an error when calling this function. Angle_DEG is returned bu a different function as:
[Angle_DEG, LinePoint1, LinePoint2] = RotatedAngle(RawImages, files, xmin, ymin, CropH, CropW, a, i);
where rotatedAngle is returning all outputs without an actual numeric value...Any ideas why this might be please? The function is defined as follows:
function [ Angle_DEG, LinePoint1, LinePoint2] = RotatedAngle( RawImages, files, xmin, ymin, CropH, CropW, a, i )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% Finding the angle for auto rotation of the image
% Then recropping to remove the black edges due to rotation
%% Finding the Image rotation based on the initial image %%
file_name = files(i).name;
im = imread([RawImages '\' file_name]);
ig = rgb2gray(im(:,:,1:3));
I = imcrop(ig,[xmin(i) ymin(i) CropW(a) CropH(a)]);
%%% Using edge detection %%%
Bw = imbinarize(I, 24/255);
IE = edge(Bw,'canny');
%IE = edge(I,'canny',0.25); %IE = edge(I,'canny',0.23)
%% Getting data points for the tile %%
% (X1,Y1) Point on the left
X1 = round((size(IE,2))*1/10);
X1line = IE(:,X1);
Y1s = find(X1line==1,500);
Y1s(Y1s == 0) = inf;
LinePoint1 = max(Y1s,[],1);
% (X2,Y2) Point on the right
X2 = round((size(IE,2))*9/10);
X2line = IE(:,X2);
Y2s = find(X2line==1,500);
Y2s(Y2s == 0) = inf;
LinePoint2 = max(Y2s,[],1);
%Y2Table(i) = Y2;
%Angle between the line and the horizontal
Coordinates = [X1,LinePoint1;X2,LinePoint2];
Dist = pdist(Coordinates,'euclidean'); % not necessary
Angle_DEG = atan2(LinePoint2-LinePoint1,X2-X1)*180/pi;

채택된 답변

Max Heiken
Max Heiken 2021년 6월 10일
It seems to me Cy and Cx must be column vectors, that is how I could reproduce the error. The function can only handle scalars for Cy and Cx. If you need to rotate your image around many points, I suggest you do it in a loop instead.
  댓글 수: 6
Max Heiken
Max Heiken 2021년 6월 10일
It is not possible to answer that without knowing the data or the goal.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by