Plotting on background image of GUI
이전 댓글 표시
I have to plot some data on an image. When I am doing this with GUI after loading image, the image disapperas.
Here is my code.
global varTrend
f = figure('Visible','on','Name','',...
'Menubar','none','Toolbar','none', 'Units', 'points','NumberTitle','off',...
'Position',[0,0,1366,768],'Resize','on','color',[127 127 127]./255); % window
GazePanel = uipanel('Parent',f,'HandleVisibility','callback','Units','normalized' ...
,'Position',[0 0 1 1],'BackgroundColor',[127 127 127]./255); % Panel within the window
varTrend = axes('Parent',GazePanel,'HandleVisibility','callback', ...
'NextPlot','replacechildren','Units','points','Position', ...
[0,0,1366,768],'FontSize',8,'Color',[127 127 127]./255); % Axis within the window
imshow('D:\GUI.png','Parent',varTrend); % show the image
% This code is doing plotting on varTrend axis
count = 1;
for i=1:length(x_coordinate(1:300))
for j = 1:length(AOI_each)
if (x_coordinate(i)>=AOI_each(j,1)&&x_coordinate(i)<=AOI_each(j,2)&& ...
y_coordinate(i)>=AOI_each(j,3)&&y_coordinate(i)<=AOI_each(j,4));
AOI(i)=j;
if i ~=1
if AOI(i)~=0
saccade = i -1;
if AOI(i-1) ==0
idx = max(find(AOI(1:i) ~=0));
saccade = idx;
end
% giving weightage to each AOI
if AOI(i-1) == AOI(i)
count = count + 1;
scatter(varTrend,AOI_centroid(j,1),AOI_centroid(j,2),count*20,'filled','r')
hold on
end
if AOI(i-1) ~= AOI(i)
count = 1;
scatter(AOI_centroid(j,1),AOI_centroid(j,2),600,'filled','r')
hold on
plot(varTrend,[AOI_centroid(AOI(saccade),1) AOI_centroid(AOI(i),1)], ...
[AOI_centroid(AOI(saccade),2) AOI_centroid(AOI(i),2)],'-r','LineWidth',2)
end
xlim([0 1920])
ylim([0 1080])
pause(0.0001)%drawnow
hold on
else
break;
end
end
end
end
end
답변 (1개)
Image Analyst
2021년 2월 6일
Of course we can't run your image for several reasons but I'm guessing is that you called scatter() or plot() before "hold on" was applied. Try calling hold on immediately after imshow():
imshow('D:\GUI.png', [], 'Parent',varTrend); % Show the image
hold on;
댓글 수: 6
Mohammed Aatif Shahab
2021년 2월 7일
Image Analyst
2021년 2월 7일
That's not the error we get. The error we get is:
Error using images.internal.getImageFromFile (line 13)
Cannot find the specified file: "E:\aatif\D_DriveBackup\data\before24june\GUI.png".
Why do you think we get that we get that error? Do you see any way we can avoid getting that error so we can do on to get the error that you get?
If I replace your image with the standard peppers.png demo image I get this:
Unrecognized function or variable 'x_coordinate'.
Error in test6 (line 17)
scatter(varTrend,x_coordinate(i),y_coordinate(i),400)
I'll check back later tonight.
Image Analyst
2021년 2월 7일
This runs without error but I don't really know what you're planning
close all;
clear vars
clear global
global varTrend
f = figure('Visible','on','Name','',...
'Menubar','none','Toolbar','none', 'NumberTitle','off',...
'Resize','on','color',[127 127 127]./255); % window
GazePanel = uipanel('Parent',f,'HandleVisibility','callback','Units','normalized' ...
,'Position',[0 0 1 1],'BackgroundColor',[127 127 127]./255); % Panel within the window
varTrend = axes('Parent',GazePanel,'HandleVisibility','callback', ...
'NextPlot','replacechildren','Units','points','Position', ...
[0,0,1920,1080],'FontSize',8,'Color',[127 127 127]./255); % Axis within the window
f.WindowState = 'maximized';
rgbImage = imread('peppers.png');
[rows, columns, numColorChannels] = size(rgbImage)
imshow(rgbImage, 'Parent',varTrend);
axis('on', 'image');
%imshow('E:\aatif\D_DriveBackup\data\before24june\GUI.png', [], 'Parent',varTrend); % Show the image
hold on;
x_coordinate = columns * rand(1, 100);
y_coordinate = rows * rand(1, 100);
plot(varTrend, x_coordinate, y_coordinate, '.', 'markerSize', 40)
xlim([0 1920])
ylim([0 1080])
drawnow
hold off
Mohammed Aatif Shahab
2021년 2월 8일
Image Analyst
2021년 2월 8일
What is the gaze panel for? Why not just simply call imshow, hold on, then plot or scatter? Why are you doing all kinds of special, fancy stuff wtih the controls?
Mohammed Aatif Shahab
2021년 2월 9일
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
