Error: Expected input to be a vector

22 views (last 30 days)
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');
%imshow(IE);
%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;
end

Accepted Answer

Max Heiken
Max Heiken on 10 Jun 2021
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 Comments
Teshan Rezel
Teshan Rezel on 10 Jun 2021
Hi @Max Heiken, it seems to be failing at the line
X1line = IE(:,X1);
which is returning a column of zeros...throwing everything that follows off!
Do you know a way around this please? I'm not sure why its behaving like this.
Max Heiken
Max Heiken on 10 Jun 2021
It is not possible to answer that without knowing the data or the goal.

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!