Filter löschen
Filter löschen

Loop counter subtraction in a GUI

1 Ansicht (letzte 30 Tage)
Jorge Cossio
Jorge Cossio am 25 Feb. 2020
Hello,
I am using the following code to scroll through an image series and selecting an ROI from each. My issue is in trying to implement an 'undo' function within a "For" loop.
Images are loaded and identified by a common naming convention (ending in: 001,002,00x, xxx). Once images are loaded an ROI is selected, the loop counter increments, and the file name is updated based on the change of the loop counter. In each iteration of the loop, the code checks for a 'undo' variable that would indicate for the previously selected ROI to be deleted, rather than add a new one. Within the 'undo' loop, I included a subtraction to the counter variable so that the image series would revert and display the same image again rather than count up to the next one.
My issue is that although the ROI is removed as intended, and it seems the 'k' counter variable is affected by the subtraction, the GUI will not display the previous image and continues on to the following image in the series even though the value of 'k' was lowered. I am not sure what is happening, and I have not been able to get that to work.
My code is below, the top and lower part of the for loop are near identical with exception that if k=1 then the variable 'Iconc' is initiated.
% --- Executes on button press in LoadSeriesButton.
function LoadSeriesButton_Callback(hObject, eventdata, handles)
% hObject handle to LoadSeriesButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path] = uigetfile({'*.jpg';'*.jpeg';'*.tiff';'*.tif'});
image = imread([path file]);
filePattern = fullfile(path, '*.tif');
files = dir(filePattern);
numOfFiles = length(files); %Looks at total files in folder to determine number of segments - Images need to be segregated by Pre/Post-stain & scale
sprintf('Total number of image files = %d', numOfFiles)
Iconc = [];
handles.cropFile = file;
guidata(hObject,handles)
handles.cropPath = path;
guidata(hObject,handles)
handles.numOfFiles = numOfFiles;
guidata(hObject,handles)
axes(handles.cropAxes)
height = round(29*2); %Temporary
width = round(29*49); %Temporaty " "
for k = 001:numOfFiles
file = file(:,1:(size(file,2)-7));
file = [sprintf('%s%03d',file, k) '.tif']
image = imread([path file]);
if k == 1 %1st image loop, establishes image matrix
axes(handles.cropAxes)
S = [0 0 width height]; %the size of your ROI starts at point 1,1 with size specified after in x and y
imshow(image);
grid on;
h = drawrectangle(gca,'Position', S, 'Rotatable', true,'LineWidth',1); %Rotation not compatible as of 2/22/20
position = customWait(h);
if get(handles.undoBox,'Value') == 1
Iconc_Old = Iconc;
k = k-001; %% SUBTRACTING FROM K TO AFFECT FILENAME
axes(handles.stitchAxes)
imshow(Iconc)
elseif get(handles.undoBox,'Value') == 0
I2 = imcrop(image,position);
Iconc = I2;
Iconc_Old = Iconc;
axes(handles.stitchAxes)
imshow(Iconc)
%%Undo button segment
end
else
axes(handles.cropAxes)
S = [position(1) position(2) width height]; %the size of your ROI starts at point 1,1 with size specified after in x and y
imshow(image);
h = drawrectangle(gca,'Position', S, 'Rotatable', true,'LineWidth',1);
position = customWait(h);
if get(handles.undoBox,'Value') == 1
Iconc = Iconc_Old;
k = k-001; %SUBTRACTING FROM K TO AFFECT FILENAME
axes(handles.stitchAxes)
imshow(Iconc)
elseif get(handles.undoBox,'Value') == 0
I2 = imcrop(image,position);
Iconc_Old = Iconc;
Iconc = [I2; Iconc];
axes(handles.stitchAxes)
imshow(Iconc)
%%Undo button segment
end
end
end

Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by