Improfile of images in cell array in for loop

12 views (last 30 days)
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]);

Accepted Answer

DGM on 12 Apr 2022
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.

Sign in to comment.

More Answers (0)


Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!