Iphonesdk boundries checking for coloring - iphone

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?

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.

Read "simple" transparent PNG in Matlab

I am trying to use PNG images as Toolbar icons. I am currently reading them with imread an set the corresponding CData value.
Now I have some images with transparency. There is no alpha channel (I found some threads with solutions for that), but I get some kind of "Simple Transparency". The imfread function returns "simple" for the Transparency field and a vector of values between 0 and 1 for the SimpleTransparencyData field.
I couldn't find any information about this transparency type neither in the Matlab help nor the internet. So I would like to know if it is possible to show the transparent image in the toolbar directly, or if not how to composite the transparent values with the toolbar's background color.
In summary you set the CData value to be a NaN to represent transparency.
See this article that I wrote on undocumentedmatlab.com which describes how to do it for uicontrols.
For a toolbar icon you modify the CData property in the same way - the primary difference is that you dont need to modify the backgroundcolor property.
I did a quick test on the only solution I could probably imagine and it really seems to work:
I forgot to mention, that I am using indexed PNG files for this. But this sort of transparency seems to imply this fact.
The indexed colors are ordered that the (partially) transparent colors are at the beginning of the table. The SimpleTransparencyData now specifies the transparency of each of the indexed colors. Non-transparent colors are left out, as there are more colors than transparency values.
With that additional information it is easy to composite a single background color with the image.

Psychtoolbox - Filloval

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.

MATLAB: display RGB values of a fits image

I want to read a .fits image of wide field sky and display the RGB values contained in a star. Can you please suggest a method to do so?
I have used fitsread to read in the image but i am not able to show the RGB values for specific locations(star).
In order to do this, you'll need a proper rgb fits file. The only .fits viewer I know of, ds9, does not support saving rgb fits files, but rather as the three separate (r,g,b) fits images. You can use "getpix" from wcstools (http://tdc-www.harvard.edu/wcstools/) or scisoft (http://www.eso.org/sci/software/scisoft/) on the individual frames. Note that "getpix" returns the pixel value given an image (x,y) location. ds9 does not provide the physical image location, but rather the wcs coordinates, so you may have to convert to image coordinates before calling getpix.

How can I adjust the RGB pixel data of a UIImage on the iPhone?

I want to be able to take a UIImage instance, modify some of its pixel data, and get back a new UIImage instance with that pixel data. I've made some progress with this, but when I try to change the array returned by CGBitmapContextGetData, the end result is always an overlay of vertical blue lines over the image. I want to be able to change the colors and alpha values of pixels within the image.
Can someone provide an end-to-end example of how to do this, starting with a UIImage and ending with a new UIImage with modified pixels?
This might answer your question: How to get the RGB values for a pixel on an image on the iphone
I guess you'd follow those instructions to get a copy of the data, modify it, and then create a new CGDataProvider (CGDataProviderCreateWithCFData), use that to create a new CGImage (CGImageCreate) and then create a new UIImage from that.
I haven't actually tried this (no access to a Mac at the moment), though.