How to plot real time graph for images batch processing?

4 views (last 30 days)
How to plot the variable handles.sum_erode versus frame number,k in the following programming?
The graph should be able to update parallel with the frame by frame processing.
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
%button used to start the batch processing of the loaded video file------
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set (handles.pushbutton1 , 'enable' , 'off');
set (handles.pushbutton3 , 'enable' , 'off');
for k = 1 :1: handles.numFrames
gambar = handles.vidFrames(:,:,:,k);
set(handles.text8,'String',k);
imshow(gambar, 'Parent', handles.axes3);
drawnow;
handles.image=gambar;
red=handles.image(:,:,1);
green=handles.image(:,:,2);
blue=handles.image(:,:,3);
B=rgb2gray(handles.image);%RGB image convert image to grayscale image
%image processing(filtering and segmentation)
.
.
.
%using morphology
se=strel('disk', 5);
sel= strel('disk',1);
SE = strel('square',2);
clos_im=imclose(bw,se);
erod_im=imerode(clos_im,sel);
erod_im2=imerode(erod_im,SE);
imshow(erod_im2, 'Parent', handles.axes1);
drawnow;
figure,imshow(erod_im2) %show the processed image
%to plot histogram frame by frame
tgray= B.*uint8(erod_im2);
t=tgray(tgray>0);
ee=hist(t,0:255);
axes(handles.axes2),bar(ee);
drawnow;
handles.sum_erode=sum(sum(erod_im));
%coding to plot the real time graph but didn't workk!!
figure,hold on;
plot(k,handles.sum_erode );
drawnow;
pause(0.5);
end

Answers (1)

Image Analyst
Image Analyst on 12 Apr 2015
k is only a single number, not a vector with the same length as handles.sum_erode, so you need to make it into a vector. Try this:
plot(1:k, handles.sum_erode, 'b-', 'LineWidth', 2);
xlabel('k', 'FontSize', 14);
ylabel('sum_erode', 'FontSize', 14);
grid on;
drawnow;
  2 Comments
Syuhada Nurull
Syuhada Nurull on 14 Apr 2015
Have run the code, but it plots many graphs, one for every k. I intend to plot only one graph that update itself.
Iv found some example in web but it use while loop for the graph plotting. If u see, my coding has already got a for loop , iv tried to put a while(k<handles.numFrames) loop for graph plotting inside the for k=1:1:handles.numFrames loop but it turn out the program keep looping only the while loop wthout stopping
Image Analyst
Image Analyst on 14 Apr 2015
You must have "hold on" somehow. Put
hold off;
cla reset
right before the plot to clear out any prior plots.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!