How to store individual return value of a function

10 ビュー (過去 30 日間)
Tipu Sultan
Tipu Sultan 2019 年 4 月 25 日
コメント済み: Tipu Sultan 2019 年 4 月 26 日
I want to store individeual return values to a variable
The code is as follows:
function tri=imageReadFromFolder()
something!
tri=[z,distance,angle];
end
As can be seen it basically reads set of images from a folder and for each image it will have individual 'z,distance,angle' .But after it reads it only shows the result for the last images.
Any help on how to solve this will be highly appreciated.
  2 件のコメント
Jan
Jan 2019 年 4 月 25 日
編集済み: Jan 2019 年 4 月 25 日
The question is not clear. What is "something!"? Where does "z,distance,angle" come from? It cannot be seen (especially not "basically"), that a set of images is read here. There is no code to read images, there I cannot guess, why the data of the "last" image are replied only. Most likely you use a loop and write:
for k = 1:numel(images)
img = import_image()
z = fcn(Img)
end
instead of
z(k) = fcn(Img)
% ^^^
Please edit your question and post some working code, which reproduces the problem. If we guess, what the problem is, the answers will be more or less unrelated.
Tipu Sultan
Tipu Sultan 2019 年 4 月 26 日
I am giving you the whole code:
function tri=imageReadFromFolder()
D = 'C:\Users\Tipu_Standard\Desktop\testIMAGES';
S = dir(fullfile(D,'Original*.jpg')); % pattern to match filenames.
for i = 1:numel(S)
F = fullfile(D,S(i).name);
I = imread(F);
B = rgb2gray(I);
A=adapthisteq(B);
% Display the original image
figure,imshow(A);
distance =0;
angle=0;
rmin=8;
rmax=30;
% Find all the circles with radius >= 8 and radius <= 30
[centersdark,radiidark] = imfindcircles(A,[rmin rmax],'Objectpolarity','dark','Sensitivity',0.913);
k=numel(radiidark);
viscircles(centersdark,radiidark ,'EdgeColor','b');
if(k==0)
z=0;
else
z=1;
p=2*radiidark;
f=2.1;
w=62;
h=144;
s=2.88;
distance=(f*w*h)/(p*s);
a=(192/2)-centersdark(1);
b=144-centersdark(2);
angle=atan2(a,b)*(180/pi);
end
tri=[z,distance,angle];
end
end

サインインしてコメントする。

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 4 月 26 日
編集済み: KALYAN ACHARJYA 2019 年 4 月 26 日
Inputs in Main script help to change the input easily.
Main scripts:
D = 'C:\Users\Tipu_Standard\Desktop\testIMAGES';
S = dir(fullfile(D,'Original*.jpg')); % pattern to match filenames.
for i = 1:numel(S)
F = fullfile(D,S(i).name);
I = imread(F);
% Next line changes required, k{i}, I missed the account the size of function output please check the below @Stephen Comment
k(i)=fun1(I);
end
Here k gives the values of individual images, like k(1),k(2)...
Make the different function file
function tri=fun1(I)
B=rgb2gray(I);
A=adapthisteq(B);
% Display the original image
figure,imshow(A);
distance =0;
angle=0;
rmin=8;
rmax=30;
% Find all the circles with radius >= 8 and radius <= 30
[centersdark,radiidark] = imfindcircles(A,[rmin rmax],'Objectpolarity','dark','Sensitivity',0.913);
k=numel(radiidark);
viscircles(centersdark,radiidark ,'EdgeColor','b');
if(k==0)
z=0;
else
z=1;
p=2*radiidark;
f=2.1;
w=62;
h=144;
s=2.88;
distance=(f*w*h)/(p*s);
a=(192/2)-centersdark(1);
b=144-centersdark(2);
angle=atan2(a,b)*(180/pi);
end
tri=[z,distance,angle];
end
  9 件のコメント
Tipu Sultan
Tipu Sultan 2019 年 4 月 26 日
thank you all :)
Tipu Sultan
Tipu Sultan 2019 年 4 月 26 日
yes it worked thanks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by