Modify UIImage RGB CMY colors - ios

First of all I'm working with OCR and I have done a huge research about it, now I got to a conclusion of what exactly I need to do, working with OCR require the UIImage to be black and white converted. Now only this specifications worked for me but I needed to do it in iOS (Swift or Objective-c) code but honestly I couldn't find a good resource which helps me to modify the image RGB CMY in the image for a percentage like Adobe Photoshop does.
I really don't need to modify RBG only, its a combination which will generate a valid UIImage and works perfectly with OCR. Truly I don't have much experience in converting UIImage pixels.

Related

Which program or format to use for texture compression

I have big image textures (4-12MB) and have resized them as much as I can without losing too much detail and would like to further compress them. Online compressors compress the 12.6MB image to 6MB without any problems, but Xcode doesn't support it (even though the compressed image is still .png), apparently because indexed color spaces are not supported for bitmap graphics contexts (according to CGBitmapContextCreate documentation and another post) and the compressed image uses them. If I try to use it I get an error:
CGBitmapContextCreate: unsupported color space.
I was looking through Apple documentation about compression and supported formats, but all I can find is information about how to compress images in code. I want to be able to apply an compressed (or otherwise reduced in size) image in the editor itself and not later in code. Is this possible?
If it is not possible to do this using a program, how should this be done via code in Swift? I found a lot of objective-C posts about this, but none that uses Swift.
Important: iOS does not support device-independent or generic color spaces. iOS applications must use device color spaces instead.
Use CGColorSpaceCreateDeviceRGB as the color space.

SVGKit performance and should it be preferred over PNG?

I have been looking at SVGKit and I am finding conflicting ideas. Some say it's slower than PNG and others saying it is fast.
I was hoping to get a recommendation and which route I should take. When I am exporting my vector graphics to PNG for display, would it not make sense to use an SVG instead ?
Of course this gives the added value that it remains a vector.
Or is it still recommended in exporting everything to a PNG ?
You might consider the middle-way introduced in Xcode 7. Here you add your assets to the project as vector images (PDF) and at build-time Xcode automatically generates the PNGs in all needed sizes (1x, 2x, 3x).
Personally, I only use SVGs when necessary, like if I need to be able to change the color of the (parts of the) image. I believe there can be a performance hit when resizing vector images at run-time, although Android uses vectors as default, so it might be insignificant.
SVG is most resource intensive and can be used if you need to display something that can be zoomed in and out while PNG should be preferred for most UI graphics (logos, icons, etc.), as it is crisp yet remains lightweight and fast to display so there is no way to compare SVG with PNG in term of Performance.
if you are going after a Crystal clear images you can use pdf based graphics, which are supported by Xcode Using Vector Images in Xcode
if you still need to implement SVGKit i always suggest using some tools (like SVGCleaner) to clean and simplify SVG in order to enhance performance.

iOS image quality improvement

Icons Are Pretty Right?
I'm working on an UI update in an iOS app, and trying to make things look a bit better with some new icons- but I seem to be incapable of determining how to save an image correctly so that it looks good in the interface!
As you can see from this image, if I include a white background with the image it looks great. If I take those same images and use an alpha background they look terrible! It appears that either the images aren't using the #2x correctly, or something else is going horribly wrong.
These images are either saved with GIMP as a png with alpha, or exported from inkscape, the originals are vector graphics. We get the same results from both avenues. I am using both a base imageName.png and imageName#2x.png for scaling.
Somehow, magically, I changed the a single image to greyscale in gimp, and changed the base size to 25px and it showed up with alpha correctly blended. Stock images from apple are also functioning correctly, so it absolutely seems to be something that I'm doing incorrectly when I'm saving the images.
The Setup in XCode
Basic Questions
Is there a certain bit depth, argb vs rgba format, or some other quirk that I need to know to get these images to show up correctly? Is there any way to verify that the program is loading the correct imageName#2x vs imageName? Is there some document that talks about integrated graphics (the iconography documentation isn't very helpful on technical details)
Actual Images
With Background:
Without Background:
I think you will find success if you just save the image at 4x the size you actually want and specify the size manually.

iOS - Save UIImage as a greyscale JPEG

In my app, I convert and process images.
from colour to greyscale, then doing operations such as histogram-equalisation, filtering, etc.
that part works fine.
my UIImage display correctly, I also save them to jpeg files and it works.
The only problem is that, although my images are now greyscales, they are still saved as RGB jpegs. that is the red, green and blue value for each pixel are the same but it still waste space to keep the duplicated value, making the file size higher than it could be.
So when i open the image file in photoshop, it is black & white but when I check "Photoshop > Image > Mode", it still says "RGB" instead of "Greyscale".
Anyone know how to tell iOS that the UIImageJPEGRepresentation call should create data with one channel per pixel instead of 4?
Thanks in advance.
You should do an explicit conversion of your image using CGColorSpaceCreateDeviceGray() as color space which is 8 bits per component, 1 channel.

CMYK vs sRGB - which one is better

Guys i have 2 images one with CMYK color model and other with sRGB.. I would like to find out which color model is better to use while dealing with image processing like resizing, cropping, color filling etc..
Thanks in advance guys.. !
CMYK color space is used for print, (s)RGB is used for screens (web, monitors, tvs etc). If one were to open a CMYK document in a viewer/program that doesn't support the color profile (which is not uncommon, since CMYK isn't as widely supported as RBG) the colors would appear to be extremely over-saturated. If you are altering the images for use on the web, or in an application, I would highly recommend that you use some variant of RGB.
In short, neither is really better than the other in general, it all depends on where you will be using the images (apples and oranges, comes to mind). CMYK is better for print, and (s)RGB is better for screens.
UPDATE in response to OP's comment:
Just to be clear (forgive me if you already know this) color space/profiles do not affect the resolution of an image, they only affect how the colors are handled/encoded. Resolution is only affected by file dimensions, DPI/PPI (dots/pixels per inch) and compression.
UPDATE 2 in response to OP's comment:
I'm not familiar with "Imagemagick", but in general, I can tell you that I've converted thousands of documents to RGB from CMYK (and vise versa) and never noticed any degradation in quality, when the file is viewed in a program that supports the color profile. The only exception is when converting to CMYK FROM RGB, it is possible to lose a wee bit of vibrancy (due to the fact that CMYK is a smaller color space. Like I said before, if by "quality" you mean "resolution" the color profile won't effect it, the image won't suddenly lose clarity, when switching color profiles. Let me know if you have any other questions.
Neither is "better" for these purposes. In general you should use the color space/model that best aligns with your output device, like CMYK for paper and sRGB for screen, but for manipulations (such as resize, crop) they are the same.
the best is sRGB because is larger and the color are better preserved. AdobeRGB is even better. But remember that if you want to distribute you graphic image you have to know what kind of device will be used to print/view. You may use also a AdobeRGB but when you print it, you'll be sad, because many colors of AdobeRGB cannot be seen on a paper.
Cheers

Resources