While loop does not give me back the value

I need to imshow the Rpokus, but matlab says that is not exist please help
vid=VideoReader("video.mp4");
k=200;
while hasFrame(vid)
frame=readFrame(vid);
numberOfFrames = vid.NumFrames;
framesToRead = 1:k: numberOfFrames;
for h = 1:length(framesToRead)
i=1;
while i<length(h)
thisFrame = read(vid, framesToRead(h));
RPokus=im2gray(thisFrame);
nHood=true(3);
Rpokus=rangefilt(gray,nHood);
Rpokus=medfilt2(Rpokus,[7 7]);
Rpokus=imfill(Rpokus,"holes");
SE=strel("disk",6);
Rpokus=imclose(Rpokus,SE);
Rpokus=imbinarize(Rpokus);
Rpokus = bwareaopen(Rpokus, 200); %vše tvořený méně než "n" pixely se odstraní
Rpokus=imclearborder(Rpokus);
clear edge
Rpokus=edge(Rpokus);
i=i+1;
end
end
end
imshow(Rpokus)

4 comentarios

Jan
Jan el 25 de Oct. de 2022
"matlab says that is not exist" - Do you get an error message? Then it is useful to post a copy of the complete message. It is easier to solve a problem, if it is mentioned, what the problem is.
What is the purpose of clear edge ?
Eliska Paulikova
Eliska Paulikova el 25 de Oct. de 2022
It says that the value or function Rpokus does not exist
I have a segmentation where I use the edge function it works. But I have a problem with loop. Because i need the value Rpokus will be remembered. It is my segmentation of the frames.
My goal is to split the video on frames and apply the segmentation on them which is the Rpokus and than display the last frame
Jan
Jan el 25 de Oct. de 2022
"It says that the value or function Rpokus does not exist" - sorry, this is not useful. Do not paraphrase what you understand of the messge, but post a copy of the complete message, which also mentions exactly, in which line the error occurs.
"Because i need the value Rpokus will be remembered." - as I have written in my answer, the loop is not entered. But if you fix this problem, Rpokus is overwritten in each loop iteration. If you want to store it, store it in an array.
Eliska Paulikova
Eliska Paulikova el 25 de Oct. de 2022
Unrecognized function or variable "Rpokus"
In line 72 so the last line where is imshow(Rpokus)

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 25 de Oct. de 2022
Editada: Jan el 25 de Oct. de 2022
for h = 1:length(framesToRead)
i=1;
while i<length(h)
The while loop is not entered. h is a scalar, so length(h) is 1 in all cases. After i=1, i is never smaller than 1.
Use the debugger to identify such problems. Set a breakpoint in the first line of the code and step through program line by line. Then you will see, that the contents of the while loop is nocht reached.
By the way, the contents of the while loop does not depend on i. So wouldn't it process the same data repeatedly (if it is entered at all)?

2 comentarios

Image Analyst
Image Analyst el 25 de Oct. de 2022
The while loop never gets entered so Rpokus is never instantiated so that's why you get the error. Here, invest some time here:
Eliska Paulikova
Eliska Paulikova el 25 de Oct. de 2022
Thank you

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 25 de Oct. de 2022

Comentada:

el 25 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by