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

 채택된 답변

Max Heiken
Max Heiken 2021년 6월 10일

0 개 추천

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

Teshan Rezel
Teshan Rezel 2021년 6월 10일
Hi @Max Heiken, I've checked but they are both scalars...not sure where else the error may lie!
Max Heiken
Max Heiken 2021년 6월 10일
Would you mind enabling "pause on error" in the drop down menu below the run button, then run, then in the function call stack drop down menu select rotateAround, and double check the variables pointY and pointX? My only explanation would be that they unexpectedly change at some point in your program.
Teshan Rezel
Teshan Rezel 2021년 6월 10일
@Max Heiken many thanks for this. It turns out my previous function call is outputting empty variables so my last variable input to the one I mentioned has no value, hence the error. I will update my question accordingly!
I imagine that either X1line or X2line is all zeros, which causes find to return an empty array.
X1line = IE(:,X1);
X1s = find(X1line==1,500);
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 2021년 6월 10일
It is not possible to answer that without knowing the data or the goal.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 6월 10일

댓글:

2021년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by