UIfigure value changes on a while loop
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Amit Ifrach
le 26 Juil 2024
Modifié(e) : Amit Ifrach
le 29 Juil 2024
לק"י
Hello!
I have a time series stack of cell masks of 21 timepoints. each mask has a unique gray scale value of its own.
I need to acquire a single pixel grayscale vlaue by clicking on the desired cell mask.
My strategy is to have two figures open at the same time.
The first figure will present the image of a single time sequence and after a pixel will be chosen it's grayscale value will be saved.
The second figure will present a loop of the time series to allow me for easy identification of the desired cell. I will only see it no interactions made with this loop figure.
This figure is running with a while loop, that will end only when I click and UIfigure (b) of a button, so the condition is when b.Value==0.
When I run the code, I awkwardly get an error when enetring the third while loop.
The code:
filename='17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif';
info = imfinfo(filename);
numberOfImages = length(info);
j=1;
for i= 1:numberOfImages
crntimg=imread(filename, i);
figure (1)
imshow (crntimg,[]);
impixelinfo
fig = uifigure;
b = uibutton(fig,"state", "Text","Press to end", "IconAlignment","top", ...
"Position",[100 100 50 50]);
while b.Value == 0
k=1
crntimgloop=imread(filename, j);
imshow (crntimgloop,[]);
if j<21
j=j+1;
else
j=1;
end
j
end
end
The error output:
j =
3
Invalid or deleted object.
Error in matlab.ui.control.internal.model.AbstractBinaryComponent/get.Value (line 95)
value = obj.PrivateValue;
Error in Cell_mask_identification_over_time (line 13)
while b.Value == 0
I tried to upload the mask's time series file, but it was too large.
Thanks,
Amit.
1 commentaire
Walter Roberson
le 26 Juil 2024
It is better to be more specific about the graphics operations
filename='17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif';
info = imfinfo(filename);
numberOfImages = length(info);
fig1 = figure(1);
ax1 = axes(fig1);
fig = uifigure();
b = uibutton(fig,"state", "Text","Press to end", "IconAlignment","top", ...
"Position",[100 100 50 50]);
j=1;
for i = 1:numberOfImages
crntimg=imread(filename, i);
imshow(ax1, crntimg,[]);
impixelinfo(ax1);
b.Value = 0;
while b.Value == 0
k=1
crntimgloop=imread(filename, j);
imshow(ax1, crntimgloop, []);
if j<21
j=j+1;
else
j=1;
end
j
end
end
Réponse acceptée
Himanshu
le 26 Juil 2024
Hey Amit,
The error you're encountering indicates that the button object 'b' is being deleted or is no longer valid by the time the loop is trying to access its Value property. This is probably happening because you're creating a new button in each iteration of the outer for loop, and the previous button gets deleted when a new one is created.
You can try to create the button once, outside of the for loop, and then use it in the loop. Additionally, you can handle the figure window and button more carefully to ensure they are not being recreated inappropriately.
filename = '17.07.2024 aHER2 carrier W.T cd45low+cd4+lstrckr001 cellpose stack.tif';
info = imfinfo(filename);
numberOfImages = length(info);
% Create the figure and button outside the loop
fig = uifigure;
b = uibutton(fig, "state", "Text", "Press to end", "IconAlignment", "top", ...
"Position", [100 100 100 50]);
% Create a figure for the looped images
figLoop = figure;
j = 1;
for i = 1:numberOfImages
% Display the current image
crntimg = imread(filename, i);
figure(1)
imshow(crntimg, []);
impixelinfo
while b.Value == 0
% Display the looped images in a separate figure
figure(figLoop);
crntimgloop = imread(filename, j);
imshow(crntimgloop, []);
pause(0.1); % Pause for a short while to make the loop viewable
if j < 21
j = j + 1;
else
j = 1;
end
end
% Reset the button value to 0 for the next iteration
b.Value = 0;
end
% Close the figures after the loop
close(figLoop);
close(fig);
High level explanation of this code;
The code reads a series of cell mask images from a TIFF file and allows the user to identify and interact with specific pixels. A state button is created outside the main loop to control the flow of the image display. The first figure displays each image in sequence for pixel value identification, while a second figure loops through the time series of images to help the user identify the desired cell mask. The loop continues until the button is pressed, and the button's state is reset after each iteration to facilitate the next image
Hope this helps!
3 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!