UIImage Fill Pattern Color - swift

For Example, I have the below image used for demo purpose only
Fill close portion with pattern
if user tap on any part of T-Shirt, than T-Shirt should be filled with selected pattern image.
I have used to find an array of the point contains close area it takes time as well to find close region points and try to draw color at that points, but it takes too much time to draw because there are many points for the close region.
I have used code from below link
https://github.com/Chintan-Dave/UIImageScanlineFloodfill
This algorithm is actually for flood fill, but I have added one more method to collect all points to one NSSet.
A help is too much appreciated.
Thanks in advance.

Related

If I have 4 coordinates making a rectangle, how can I color in that area?

I have 4 coordinates assigned to variables, so I would just like to colour in the rectangle that is created from these variables. I tried the fill function, but I cant gather much information from the example.
When I try to use:
fill(bottom left point, top right point,'g')
the figure it makes only shows a line between those points, and doesn't colour in the entire area.
I'm using MATLAB R2019b, if that helps.
Also, if its possible to fill the rectangle with a pattern instead, please let me know aswell.
Thanks in advance

How do i fill this boundary of a cat with white colour using matlab?

I have already tried imfill(img) but that doesn't work at all.
I have noticed that imfill works for this purpose only for images in which the object's boundary is complete and not broken like the image i am taking .
For this particular image do the following:
Prepend a white row to the image to close the contour.
Fill the contour.
Remove the helper row.
Anything else requires more information and examples.
Matlab documentation states that "a hole is a set of background pixels that cannot be reached by filling in the background from the edge of the image". In this case any pixel can be reached from the edge because its boundary is not complete. Therefore, technically there is no hole in the image you posted.

Extract Rectangular Image from Scanned Image

I have scanned copies of currency notes from which I need to extract only the rectangular notes.
Although the scanned copies have a very blank background, the note itself can be rotated or aligned correctly. I'm using matlab.
Example input:
Example output:
I have tried using thresholding and canny/sobel edge detection to no avail.
I also tried the solution given here but it detects the entire image for cropping and it would not work for rotated images.
PS: My primary objective is to determine the denomination of the currency. There are a couple of methods I thought I could use:
Color based, since all currency notes have varying primary colors.
The advantage of this method is that it's independent of the
rotation or scale of the input image.
Detect the small black triangle on the lower left corner of the note. This shape is unique
for each denomination.
Calculating the difference between 2 images. Since this is a small project, all input images will be of the same dpi and resolution and hence, once aligned, the difference between the input and the true images can give a rough estimate.
Which method do you think is the most viable?
It seems you are further advanced than you looked (seeing you comments) which is good! Im going to show you more or less the way you can go to solve you problem, however im not posting the whole code, just the important parts.
You have an image quite cropped and segmented. First you need to ensure that your image is without holes. So fill them!
Iinv=I==0; % you want 1 in money, 0 in not-money;
Ifill=imfill(Iinv,8,'holes'); % Fill holes
After that, you want to get only the boundary of the image:
Iedge=edge(Ifill);
And in the end you want to get the corners of that square:
C=corner(Iedge);
Now that you have 4 corners, you should be able to know the angle of this rotated "square". Once you get it do:
Irotate=imrotate(Icroped,angle);
Once here you may want to crop it again to end up just with the money! (aaah money always as an objective!)
Hope this helps!

Count number of grid boxes which cover an object in an image

I have displayed grid boxes over an image. I want to count number of grid boxes which cover an object in that image
for example http://snag.gy/geFIZ.jpg. In this image I have displayed grid on image but i need to count how many girds have been taken to cover that object completely.? Kindly help me regarding this
Regards
Dams
Slow, but easy to implement way:
1) Use this topic to add lines to image.
2) Make something like this:
Make a cycle to check every box. In each box check pixels. If you found first white pixel in box, add 1 to number of covering boxes and go for next one.
No code from you - no code from me, sorry :) Good luck!

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?