Matlab Psychtoolbox PTB new textures not appearing on computer monitor - matlab

As shown by the attachment, i'm presenting multiple images on a computer monitor. I can physically view the very first one that is presented, but on the next trial, the texture's I've drawn are done correctly, but they do not appear on the display itself. I know they are done correctly because I used Screen('GetImage') to obtain the copy that you see attached here. So i'm not sure what i'm doing wrong. I'm used to using offscreenwindow's, but here i opted to draw textures on the onscreen window. This is a psychtoolbox problem.
I'm using this code to upload the image, make a texture out of it, and draw it to the onscreen window
img = imread(trial(t).nontargetImage); img = imresize(img, picResize); [iy, ix, ~] = size(img);
txtIndex=Screen('MakeTexture', expWin, img);
Screen('DrawTexture', expWin, txtIndex, [],...
[loc(i).x-(ix/2), loc(i).y-(iy/2), loc(i).x+(ix/2), loc(i).y+(iy/2),]);
and on trial 1, i'm seeing that the below appears correctly with the following code
[startRT] = Screen('flip',expWin);
But when trial 2 comes, and the expWin gets drawn to again with different textures, the expWin, when flipped, does not show anything at all (or at least i cannot see it). All i see is a black screen.

I was using Windows 7, which was the issue. When I updated the computer to windows 10, it worked!

Related

EFI_GRAPHICS_OUTPUT_PROTOCOL Blt doesn't do anything

I was trying to display something on screen using UEFI.
Almost PC which had UEFI drawed well with framebuffer.
But one PC had older UEFI and I had to draw using Blt function in EFI_GRAPHICS_OUTPUT_PROTOCOL.(Probably because that PC's IGP had no UEFI module..)
But whenever I try it, it doesn't do anything.
I tried same thing in VMware, but it doesn't work either.
This is what I have tried.
EFI_GRAPHICS_OUTPUT_BLT_PIXEL p;
p.Red = 255;
p.Green = 0;
p.Blue = 0;
EFI_STATUS status = prot->Blt(prot, &p, EfiBltVideoFill, 0, 0, 0, 0, width, height, 0);
NOTE: prot is instance of EFI_GRAPHICS_OUTPUT_PROTOCOL.
I googled and I couldn't find any problem with arguments and I checked status variable and it said EFI_SUCCESS.
That thing draws red pixel to entire screen, right?
But it didn't draw anything on screen.
I tried this after drawing something on framebuffer.(And of course, it worked pretty well on VMware)
But I couldn't see any change on screen. Not even a black screen or something else. What I could see is what I had draw using framebuffer.
Am I doing something wrong?
Of course, I haven't used ExitBootServices() yet.
Try getting all protocol handles, not just one, because some systems have multiple instances of GOP, and the first one can be a black screen (second monitor which is not connected now, etc.) you are trying to write to.

Same default figure position and size independent of screen resolution on different computers

I work with MATLAB on the right half of the screen, so I want figures to open on the left half of the screen. However, the figure height should be about the size of a default figure, so not the height of the screen. Also, I use MATLAB on different computers with variable screen sizes (pixels), so figure dimensions should depend on the screen size, but produce identical figures on screen. The figure dimensions and position are therefore dependent on the screen resolution, but the code generating the dimensions and position should be independent on it.
I've accomplished this with the code in my answer below, which I thought I'd share for anyone who finds this useful for their own setup.
The default MATLAB current folder can be set in MATLAB's preferences. I've set this to the network folder on all my MATLAB computers, this can also be a cloud folder of a cloud service, e.g. Dropbox. Then I put a file startup.m in that folder containing the following code.
ss = get(0,'screensize');
b = 7; % border around figures is 7 pixels wide
%TODO different for various operating systems and possibly configurations.
p = 0; % extra padding pixels from left edge of screen
if ispc
win = feature('getos');
i = (1:2) + regexp(win,'Windows ','end');
switch win(i)
case '10'
b = 0;
p = 2;
otherwise
% other cases will be added in the future
end
end
fwp = ss(3)/2-2*b-p; % figure width in pixels
b = b+p;
n = 5;
set(0,'defaultfigureposition',[b ss(4)/n, fwp, ss(4)*(1-2/n)])
clear
Now, every time I start MATLAB, it runs this script and it moves the default figures I create to the left half of the screen with a nice size (the axes are just a little wider than they are tall).
The figure's units are normalised, but they can be set to pixels or whatever measure you like as well. I hope someone will find this a useful script for their setup.
EDIT: I've update the script to keep the default figure units: pixels. This is necessary, because apps such as the curve fitting tool (cftool) or the Classification Learner (classificationLearner) and probably others are bugged with normalised figure units. Their (dialog) windows either don't show up (they are positioned outside your screen area) or are too small or too large.
EDIT 2: I've updated the script for compatibility with Windows 10. The figure windows now have a border of 1 pixel, instead of 7. Also, the figures are padded a bit to the right, because Windows 10 puts them too far to the left. Windows 10 is detected automatically.
TO DO: support additional operating systems (with detection), e.g. Mac, Linux. If you have such a system, please report the following in a comment:
Open MATLAB and copy paste the resulting string from the feature getos command here.
Position the figure against (not on or over) the left edge of the screen and against (not on or over) the right half of the screen and report the figure's position and outerposition here.

MATLAB: Making a video using writeVideo

I am currently trying to make a video using the writeVideo function in MATLAB. I have made a GUI using GUIDE which includes a slider, a few checkboxs, and a single axes (tagged as axes1). When I move the slider, the axes will plot certain shapes that change according to the slider value.
What I am trying to do is record a video of the GUI being used to show the functionality in a presentation. However, when I play back the video (after making it using writeVideo), it shows the slider value moving and the checkboxes being checked correctly, but the plot never changes (i.e. it will only show the original shape). This seems to be some refresh error, however, anything I have tried has not worked (refresh, drawnow, etc.)
Any idea why this is happening? The following is the code I am trying to implement:
vidObj = VideoWriter('test.avi','Motion JPEG AVI');
open(vidObj);
flag = 0;
if flag<12 %movie will be 12 frames long
flag = flag+1;
if slider<1
plot something...
elseif slider>=1 && slider<2
plot something else...
etc...
elseif slider<=5
plot something else...
end
hFigure = findobj('Name','gui');
currFrame = getframe(hFigure);
writeVideo(vidObj,currFrame);
clear hfigure currFrame image;
else
fprintf('done\n')
close(vidObj);
end
As stated, I can then use implay to play back the test.avi file, however, the plot never updates.
Thanks in advance
Note: I am using MATLAB R2012b
EDIT:
The following is how I ended up creating my video: maybe this will help someone who was facing similar issues to the one stated above.
I basically gave up on using getframe and decided to 1) get screenshots, then 2) turn the screenshots into a movie. To get the screenshots, I first ran my program then, in the command window, invoked the following code using the java toolkit
i = 1;
while true
robo = java.awt.Robot;
t = java.awt.Toolkit.getDefaultToolkit();
%# Set screen size
rectangle = java.awt.Rectangle(0,0,1000,640);
%# Get the capture
image = robo.createScreenCapture(rectangle);
%# Save it to file
filehandle = java.io.File(sprintf('capture%d.jpg', i));
javax.imageio.ImageIO.write(image,'jpg',filehandle);
pause(.4) %# Wait for 0.4 seconds
i = i + 1;
end
This then continually ran in the background and took snap shots of the screen and stored them into the current directory. to stop it from running, just use Ctrl C. Once I had the screen shots, I used the following code to create the movie:
vidObj = VideoWriter('test.avi','Motion JPEG AVI');
open(vidObj);
for i=7:87 %these are the frames I wanted in my movie
x = num2str(i);
im = horzcat('capture',x);
im1 = horzcat(im,'.jpg')
imdata = imread(im1);
writeVideo(vidObj,imdata);
end
close(vidObj);
getframe is sometimes problematic. I'm not sure I can give an answer, and I can't simply comment because of my reputation, but this link might be of help. After you get the figure from the GUI, turn it into an image and then into a frame. Worth a shot.
If you change your monitor settings to 16 bit color it will solve the problem you are having. This has been documented on the link provided. My previous answer was deleted because I only supplied the link and told you how to solve the problem (sorry) but if you actually click on the link and see what they say or change your monitor settings to 16 bit color everything will work. From the link you can see that people have had this problem since 2009 but it was updated in april 2013 so it is still a problem and changing your monitor settings to 16 bit color is still a solution.
Hope this helps!
http://www.mathworks.com/matlabcentral/newsreader/view_thread/257389

Matlab imshow() not showing the image properly

I have a simple code to show an image in Matlab. I use imread() to read it and imshow() to show it. the code it below, and the result in not shown properly. hope someone can help me.
img = imread('/home/samuelpedro/Desktop/API - Projecto/coimbra_aerea.jpg');
figure, imshow(img);
the resulting image is below.
also, if i choose to save it to file as a new jpg it is saved correctly.
UPDATE 1:
weirdly if i choose to show the axes in the preferences>image processing, it is corrected
Locking at your screen-shot, the x- and y-ticks are missing. They should appear in a standard-configuration of Matlab. Maybe something is just messed up in the Matlab-configuration. Try to do this with a clean new ~/.matlab folder (rename the old one before).
Alternatively ... again judging by your screen-shot, this looks like Ubuntu/Unity in the background. Unity needs acceleration (OpenGL), which can be randomly buggy for some Linux graphics drivers. You may want to try to launch matlab in a "clean" X-server (maybe the twm environment) to rule this out.
Save the image as an (uncompressed) bitmap (bmp) and read it with imread. If the jpg is messed up by the imread-routine, this should rule this out.
Last but not least, broken copy of your jpg on your disk, some flipped bits. Run md5sums on your file's copies.

MATLAB: impoint getPosition strange behaviour

I have a question about the values returned by getPosition. Below is my code. It lets the user set 10 points on a given image:
figure ,imshow(im);
colorArray=['y','m','c','r','g','b','w','k','y','m','c'];
pointArray = cell(1,10);
% Construct boundary constraint function
fcn = makeConstrainToRectFcn('impoint',get(gca,'XLim'),get(gca,'YLim'));
for i = 1:10
p = impoint(gca);
% Enforce boundary constraint function using setPositionConstraintFcn
setPositionConstraintFcn(p,fcn);
setColor(p,colorArray(1,i));
pointArray{i}=p;
getPosition(p)
end
When I start to set points on the image I get results like [675.000 538.000], which means that the x part of the coordinate is 675 and the y part is 538, right? This is what the MATLAB documentation says, but since the image is 576*120 (as displayed in the window) this is not logical.
It seemed to me like, somehow, getPosition returns the y coordinate first. I need some clarification on this.
Thanks for help
I just tried running your code in MATLAB 7.8.0 (R2009a) and had no problems with image sizes of either 576-by-120 or 120-by-576 (I was unsure which orientation you were using). If I left click inside the image, it places a new movable point. It did not allow me to place any points outside the image.
One small bug I found was that if you left-click in the image, then drag the mouse pointer outside the image while still holding the left button down, it will place the movable point outside the image and won't display it, displaying a set of coordinates that are not clipped to the axes rectangle.
I'm not sure of what could be your problem. Perhaps it's a bug with whatever MATLAB version you are using. I would suggest either restarting MATLAB, or clearing all variables from the workspace (except for the image data im).
Might be worth checking to see which renderer you are using (Painter or OpenGL), a colleague showed me some wierd behaviour with point picking when using the OpenGL renderer which went away when using the Painter renderer.
Your code uses the Image Processing Toolbox, which I don't have, so this is speculation. The coordinate system is probably set to the figure window (or maybe even the screen), not the image.
To test this, try clicking points outside the image to see if you can find the origin.