Improfile of images in cell array in for loop

조회 수: 9(최근 30일)
lena kappa
lena kappa 2022년 4월 12일
댓글: lena kappa 2022년 4월 12일
Hello everyone i want to take the profiles of some images i have stored in a cell array but i can't figure out how to do it
Here is my code:
x = [1 301];
y0 = [1 189];
outLoop = [2,4]
outLoop1 = [1, 3, 5];
for r = 1 : numel(outLoop)
r = outLoop(r);
for m = 1 : numel(outLoop1)
m = outLoop1(m);
plot(improfile(images{1, al, m, 1},x,y0),'LineWidth',2)
I get the error :
Unrecognized function or variable 'dx'.
Error in improfile (line 168)
d = bsxfun(@rdivide,pCoordinates,[dx dy]);

채택된 답변

DGM 2022년 4월 12일
I have no idea how your cell array is shaped (is it actually a 4D cell array?) and there's no indication where the variable 'al' came from.
If I have to interpret what this means, I'm just going to assume the cell array is 2D. If it's not, then you'll have to adapt the example.
% read an image, replicate it
A = imread('peppers.png');
images = repmat({A},5,5);
% modify each copy so the profiles vary
for k = 1:numel(images)
images{k} = imnoise(images{k},'gaussian',0,0.01);
% path coordinates
x = [1 301];
y = [1 189];
% use at least somewhat meaningful variable names
idxr = [2 4]; % row indices of images
idxc = [1 3 5]; % col indices of images
nr = numel(idxr);
nc = numel(idxc);
k = 1;
for kr = 1:nr
for kc = 1:nc
subplot(nr,nc,k) % put things in separate subplots
k = k+1;
Passing the output of improfile() to plot() doesn't work like that. Unless you actually specify output arguments, improfile() plots the profile itself. If you want to use plot(), call improfile() separately with an appropriate number of output arguments, then use those outputs to construct something that's appropriate for plot() to use.
  댓글 수: 3
lena kappa
lena kappa 2022년 4월 12일
Thank you very much @DGM!!! :)

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by