How to find out if CGImageRef is completely?

I am writing an Objective-C algorithm that compares two images and displays the differences.

Sometimes two identical images are transmitted. Is there a way to immediately indicate from the resulting CGImageRef that it does not contain data? (i.e. only transparent pixels).

The algorithm runs at> 20 frames per second, so performance is a top priority.

+4
source share
3 answers

Here you have to go with CoreImage. Check out the CIArea * filters.

See the link to the main image filter here: http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CoreImageFilterReference/Reference/reference.html

This will be much faster than any of the previous approaches. Let us know if this works for you.

+2
source

In terms of performance, you should include this check in your comparison algorithm. The most expensive operation when working with images is the majority of loading a small part of the image into the cache. Once you receive it, there are many ways to work with data very quickly ( SIMD ), but the problem is that you need to evict and reload the cache with new data all the time, and it is expensive to calculate. Now, if you already went through each pixel of both images once in your algorithm, it would be advisable at the same time to calculate the SAD , while you still got the data in the cache. So in the pseudo code:

int total_sad = 0 for y = 0; y < heigth; y++ for x = 0; x < width; x+=16 xmm0 = load_data (image0 + y * width + x) xmm1 = load_data (image1 + y * width + x) /* this stores the differences (your algorithm) */ store_data (result_image + y * width + x, diff (xmm0, xmm1)) /* this does the SAD at the same time */ total_sad += sad (xmm0, xmm1) if (total_sad == 0) print "the images are identical!" 

Hope this helps.

+2
source

Not sure about this, but if you can have an image sample of a completely clean image already exists, then

 UIImage *image = [UIImage imageWithCGImage:imgRef]; //imgRef is your CGImageRef if(blankImageData == nil) { UIImage *blankImage = [UIImage imageNamed:@"BlankImage.png"]; blankImageData = UIImagePNGRepresentation(blankImage); //blankImageData some global for cache } // Now comparison imageData = UIImagePNGRepresentation(image);// Image from CGImageRef if([imageData isEqualToData:blankImageData]) { // Your image is blank } else { // There are some colourful pixel :) } 
+1
source

Source: https://habr.com/ru/post/1489261/


All Articles