Psychtoolbox - Filloval - matlab

I am new to Matlab and Psychtoolbox. I need to change color saturation. When creating a circle Screen('FillOval',window, is there a way of getting a handler to the Oval object and is it rendered as image? Thanks in advance

Unfortunately, (as far as I know) the FillOval function doesn't create a handle like you would be used to with matlab figures / patches. The best way to change the color is simply with the RGB index argument.
If you forget the arguments that belong in Psychtoolbox functions, type the name with a question mark to see the help file. In this case, type this in the command line:
Screen('FillOval?')
The arguments are:
Screen('FillOval', windowPtr [,color] [,rect] [,perfectUpToMaxDiameter]);
If i wanted to change the saturation, I would just redraw the Oval and change the RGB values I filled into the Fill Oval function. e.g. put in [255,0,0] on the first flip and [255,50,50] on the second.
It kind of sounds like you may want to opt for the "MakeTexture" and "DrawTexture" functions. With this function, you can take any image matrix and transform it into a texture handle with "MakeTexture". With "DrawTexture" you can then draw the image into the psych toolbox window. DrawTexture is nice, because it allows you to easily change the opacity of the texture.
I recommend exploring the help functions to learn more about this option.

Related

Image segmentation algorithm in MATLAB

I need to implement an image segmentation function in MATLAB based on the principles of the connected components algorithm, but with a few modifications. This is intended for very simple, 2D images, with a background color and some objects in different colors.
The idea is that, taking the image as a matrix, I provide a tool to select the background color (it will vary for every image). Then, when the value of the color of the background of the image is selected, I have to segment all the objects in the image, and the result should be a labeled matrix, of the same size of the image, with 0's for the background, and a different number for each object.
This is a graphic example of what I mean:
I understand the idea of how to do it, but I do not know how to implement it on MATLAB. For each pixel (matrix position) I should mark it as visited and then if the value corresponds to the one of the background, assign 0, if not, assign another value. The objects can be formed by different colors, so in the end, I need to segment groups of adjacent pixels, whatever their color is. Also I have to use 8-connectivity, in order to count the green object of the example image as only one object and not 4 different ones. And also, the objects should be counted from top to bottom, and from left to right.
Is there a simple way of doing this in MATLAB? I know the bwlabel function, but it works for binary images only, so I'd like to adapt it to my case.
once you know the background color, you can easily convert your image into a binary mask of the same size:
bw=img!=bg_color;
Once you have a binary mask you can call bwlavel with 8-connectivity argument as you suggested yourself.
Note: you might want to convert your color image from RGB representation to an indexed image using rgb2ind before processing.

Create label for conical surface

Is it possible to create labels for conical surfaces in MS-word.
I have a label ready, but it needs to adapt to that the printed label can be pasted on a conical surface (e.g. a coffee cup)
I doubt it. You could try using WordArt: these are predefined shapes, maybe one of those matches what you want to do.
I suspect you'd be better off using a program like Adobe Illustrator, which can convert text to vector images which you can distort any way you like.
The bigger problem is that the label won't fit properly on a shape that is curved in two dimensions: you'll always have folds somewhere.

add simple geometric elements to GUIDE GUI

I am desiging a simple GUI application in Matlab using GUIDE.
I am displayed a number of axis - and I would like to add some simple design elements to make the interface clearer. I would like to draw a colored rectangle around an axis (seperate from the axis)... there are two such axes, each displaying details of some things shown in a third plot, and I would like this color clue to link the details to the overview.
So is it possible to add simple geometric shape objects to a Matlab GUI? I don't see anything but controls in GUIDE but perhaps its possible to add them manually with an explicit command?
It is generally difficult to draw any random shape. Except Square & rectangle, for which you can create panels and change the properties like BorderWidth and HighlightColor.
Since MATLAB GUI is based on Java, you can create any object in MATLAB GUI which can be created in Java. You can refer to this website [1] for further learning.
[1] http://undocumentedmatlab.com/matlab-java-book/

to draw ROIs and to calculate mean difference

I have two CT image . How can I draw multiple ROIs on both image and calculate mean difference between each the corresponding ROIs with matlab ? I've used the 'imrect' or 'imellipse' but this commands creates the Mask which makes the image as binary image then I would have problem with to calculate mean difference .
How to show the images with the ROIs draw on them?
Not very sure about what you want to do with imrect. This is an idea; the way I would do it. You have to get your hands dirty with actual programming instead of GUI, but it's VERY basic stuff, and easy as soon as you understand indexing, which is very nice in MatLab and the thing you should take with you from this answer:
First of you define the size of your ROIs, which can be easily made with a variable
width=20; %or whatever you wish
height=10;
then define the multiple ROIs using their upper left corner for the position
ROI11=Image1(corner1:corner1+width,corner1:corner1+height); %(width and height eventually the other way around, whatever)
ROI12=Image1(corner2:corner2+width,corner2:corner2+height);
%...
ROI21=Image2(corner1:corner1+width,corner1:corner1+height);
ROI22=Image2(corner2:corner2+width,corner2:corner2+height);
%...
and then calculate the mean however you please, like for example:
Mean1=sum(ROI11-ROI21)/length(ROI11(:));
Mean2=sum(ROI11-ROI21)/length(ROI11(:));
%...
or something along those lines.
Give it a try and play a bit with it.

Iphonesdk boundries checking for coloring

im creating and app where user already have an image (with different objects) without colors, i have to check the object and then color with respected color with the touch on that objects. how should i do this. can anyone help me.
I would say that that is non-trivial. I can only give hints since I have not done such an app yet.
First, you need to convert the image into a CGImageRef, for example by doing [uiimage_object CGImage].
Next you need convert the CGImageRef into array of pixel colors. You can follow the tutorial at http://www.fiveminutes.eu/iphone-image-processing/ for sample code. But for your app you need to convert the array into two dimension based on image width and height.
Then, use the coordinate of the user touch to access the exact pixel color value from the array. Next you read off the color values of the surrounding pixels and determine if color is similar to the touched pixel or not (you might need to read some wikipedia articles etc on doing the color comparison). If the color is similar, change the color to the one you want. Recurse until the surrounding color is different (i.e. you hit the boundary).
When you are finished modifying the pixel color value array, you need to convert the array back into CGImageRef using CGImageCreate function. Then you convert back to UIImage using [UIImage imageWithCGImage:imageref].
Now you are on your own to implement the steps into code. It would be unreasonable if you expect me to code all that for you, wouldn't it?