why isn't image changing when it is supposed to?

4 views (last 30 days)
THis one has me stumped for two days straight. It seems like it should be the easiest thing in the world, but there's something I'm just not getting.
I want the image to change to the next image every time bb = 3, or fstep/2, and stay on that image otherwise. There will be other images coming in at different places, so I can't just adjust the starting point, it has to change at bb=fstep/2 exactly. Nothing I code will do this, it keeps changing only at bb=1 instead. I'm mystified, can anybody see what's wrong and can suggest a change with as little modification to the original code as possible?
clear all
clf
fpath1 = '/Users/owner/Documents/MATLAB1/';
addpath(fpath1);
pI1 = 1 + [0, 1, 2];
pIsiz = size(pI1,2);
IB = {'T5 01.jpg'; 'T5 02.jpg'; 'T5 03.jpg'};
fI1B = {IB{pI1(1:pIsiz)}};
fstep = 3; % FRAME STEPS BETWEEN EACH IMAGE ----------------
bbm = [(fstep/2)+1:fstep 1:fstep/2];
fstep = fstep * 2;
cc = 1;
for aa = 1:3
astr = num2str2023(aa); % FILE NAME INCREMENT VALUE
I2 = imread(fI1B{aa});
for bb = 1:fstep
[aa bb cc]
if mod(cc,fstep) == fstep/2
I2 = imread(fI1B{aa});
fI1B{aa}
end
astr = num2str2023(aa); % FILE NAME INCREMENT VALUE
bstr = num2str2023(bb);
imf12 = [fpath1,'MTEST ' astr,' ', bstr, ' 2023.tif'];
imwrite(I2, imf12, 'tif', 'Resolution', 720);
cc = cc + 1;
end
end

Answers (2)

Walter Roberson
Walter Roberson on 27 Feb 2023
cc starts at 1.
fstep is 3.
mod() of an integer by 3 is going to be an integer.
You compare that integer to fstep/2 which is 3/2 which is a non-integer.
Therefore the mod() can only come true if at some point you increment c by a non-integer. But you never do, you only increment it by 1.
  1 Comment
mark palmer
mark palmer on 27 Feb 2023
thanks for your response!
fstep is 6 (fstep * 2) by the time it reaches the loop. bbm can be ignored

Sign in to comment.


mark palmer
mark palmer on 28 Feb 2023
I figured out the issue, thanks.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!