Improfile of images in cell array in for loop
2 次查看(过去 30 天)
显示 更早的评论
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)
end
end
I get the error :
Unrecognized function or variable 'dx'.
Error in improfile (line 168)
d = bsxfun(@rdivide,pCoordinates,[dx dy]);
0 个评论
采纳的回答
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);
end
% 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
improfile(images{idxr(kr),idxc(kc)},x,y);
k = k+1;
end
end
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 个评论
DGM
2022-4-12
You could do something like this:
% 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);
end
% 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);
for kr = 1:nr
for kc = 1:nc
improfile(images{idxr(kr),idxc(kc)},x,y);
saveas(gcf,sprintf('profile_%02d_%02d.png',idxr(kr),idxc(kc)))
end
end
You could also use exportgraphics() instead of saveas(), though I don't have a new enough version to demonstrate that.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!