iOS detect color inside UIImage and crop - ios

I'm trying to figure out the best way to approach this. I'm looking to take an UIImage, detect if there are any shapes/blobs of a specific RGB color, find their frame and crop them into their own image. I've seen a few posts of people recommending OpenCV as well as other links similar to this - Link
Here are 2 screenshot's of what I'm looking to do. So in Example 1 there is the light blue rectangle with some text inside it. I need to detect the blue background and crop the image along the black lines. Same for the red image below it. This is just showing that it doesn't matter what's inside of the color blob. Example 2 shows the actual images that will be cropped once the 2 color blobs are found and cropped. All image will always be on a white background.
Example 1
Example 2

This question goes way beyond a simple answer. What you will need to do is access the raw data on that image based on the color then create a frame to crop. I would find the upper, left,right, lower frame of all matches of that specific color then make a frame out of it to crop the image.
Access the color
Get Pixel color of UIImage
Crop the image
Cropping an UIImage

Related

Crop text image within background using OpenCV

I would like to extract the letter from the blue images shown below.
Ideally, the result would be a cropped black letter image on a white background as shown below.
There may be functions of CV that would enable me to go this effectively.
I think this would be a more simple thing to do if the original letters weren't white. It would be more simple to crop the image to the extent of the letter and change the font color to black.
Appreciate any help.
Image example 1
Image example 2
Result

iOS 'colorWithPatternImage' is adding 1 px borders around my images?

I'm using UIColor's colorWithPatternImage function to set a tiled image on one of my views. The result is a grid of 1 pixel lines all over.
Fig: The clear color grid of lines is the issue.
My intention was to obtain a perfect background using the tiled image.
I first suspected that the image I was using could be faulty, but zooming it to 800% doesn't really show the presence of any transparent one-pixel border anywhere.
Here's the image (#2x version):
Any ideas what it could be related to?
Thanks,
p.
you are doing everything fine, but your problem is that your pattern image have 1 pixel line on the top an 1 pixel line on the left side with alpha color so you only need to modify your pattern image simply as that, I have been testing and this is the problem
I hope this helps you

Stretch image border uniformly and leave center of image unstretched on iOS

Is it possible to achieve the same thing on iOS as on Android with this 9-patch file?
Result should be something like this. The flower is something on the background. Then I want to apply the gray overlay with transparent (see through, not stretched) logo in the center.
(the file is not a valid 9-patch, because of wider patch areas, but that is only for question clarity)
So basically I'd like to overlay the screen with this semi-transparent gray color and in the center would be unstretched logo - kind of cut-off from the overlay. (Notice that logo in image is completely transparent)
I tried to use image slices, but I can't define multiple slices per dimension, so just one border is resizing.
I'd like to avoid tile-ing the background from multiple views.

Color selected part of image taken from camera on touch

My requirement is to fill specific color on specific area of an image. But the image should be an image taken from iphone camera or photo gallery. For example, I could take a picture of me with a blue shirt, the app should allow me to change the color of the shirt to red.
Exactly the functionality of "Paint bucket" tool of the photoshop.
I found couple of approaches
1) Using MASKS with prepared images
color selected part of image on touch
Fill color on specific portion of image?
Scanline Flood Fill Algorithm
https://github.com/Chintan-Dave/UIImageScanlineFloodfill
2) Using GLPaint (Actually this is NOT the solution I am running after)
My question is,
Is it possible to color specific area of a image WITH OUT having MASKS or with generating masks for the image on run time?
Scanline Flood Fill Algorithm does that in to a certain level. But when it comes to real time images(like selfie images) it wont work correctly?

How to figure out, If an imagefile (base64) has transparency?

i wonder, how i could figure out if an image has a transparency effect applied. Is there any way in JavaScript or HTML5? I have a Base64-coded image. Is there a way to read out the transparency-information (alpha-channel). For example, if i load a PNG-Image, then convert it to base64, then drop it to html5-canvas, now how can i know if this has transparency-effect activated?
thanx alot
okyo
When you say 'drop it to html5-canvas', I assume you mean using an image element with the 'data:' URI scheme. Also, let's take it as given that you don't want to write javascript code to parse the image files.
You could do something like this pseudo-code:
create 2 off-screen canvases
color one opaque white and the other opaque black
draw the image on both of them
call getImageData on each canvas, using the image bounds
compare the image data
If the image has any transparent or partially-transparent pixels, then presumably the two canvases will end up at least a little different. One exception would be if the image has the transparency feature enabled but is entirely opaque anyway. Another would be if the non-opaque pixels are only very slightly transparent - not enough to alter a white or black background. But this technique would catch images where transparency is noticeable.

Resources