Current position:  Home > Default > How can I improve performance (image searching)

How can I improve performance (image searching)

Time:October 11
Advertisement
Hello,
My program makes many calls to a method that compares two images. It does this by using nested for-loops (one for x-pixel and one for y-pixel) to search through a BufferedImage image and use getRGB() to compare pixel-by-pixel to see if the two images are the same.
I've added a little bit of "optimisation" that first compares the central 5-pixles (the 5 pixels in an "X" shape in the middle of each image), and will only continue to search pixel-by-pixel if those are shown to be the same.
Of course, both searches (the optimisation-pre-search and the pixel-by-pixel search) will quit out of the loops and return false as soon as one non-matching pixel is found.
The problem is that it has to do this millions of times. For every single pixel in the source image, it has to go through one-by-one and compare, starting with the "optimised" speedy-compare and then moving on.
Advertisement
Try this:
public static boolean areImagesIdentical(File file1, File file2) throws IOException {
          // Safe to do this?
          if(file1.getAbsolutePath().equals(file2.getAbsolutePath())) {
               System.out.println("files are same - same path");
               return true;
          if(file1.length() != file2.length()) {
               System.out.println("files are different, different file size");
               return false;
          BufferedImage image1 = ImageIO.read(file1);
          BufferedImage image2 = ImageIO.read(file2);
          if(image1.getHeight() != image2.getHeight() || image1.getWidth() != image2.getWidth()) {
               System.out.println("files are different, different height or width");
               return false;
          // Take 10 pixels from anywhere in each image
          for(int i=0; i<10; i++) {
               int x = (int) (Math.random() * image1.getWidth());
               int y = (int) (Math.random() * image1.getHeight());
               if(image1.getRGB(x, y) != image2.getRGB(x, y)) {
                    return false;
          int[] image1AllRGBs = image1.getRGB(0, 0, image1.getWidth(), image1.getHeight(), null, 0, image1.getWidth());
          int[] image2AllRGBs = image2.getRGB(0, 0, image2.getWidth(), image2.getHeight(), null, 0, image2.getWidth());
          return Arrays.equals(image1AllRGBs, image2AllRGBs);
     }
Read related articles
Times ten to improve performance for search results in Oracle eBS
A64 Tweaker and Improving Performance
Using Lightroom and Aperture, will a new ATI 5770/5870 vs. GT 120 improve performance?
How to improve performance on SD document with over 1000 line items
How to improve performance on MacBook Pro 10.5.8?
FI-CA events to improve performance
How to preload sound into memory to improve performance?
How to improve performance of MediaPlayer?
How to improve performance when there are many TextBlocks in ItemsControl items?
How to improve Performance of the Statements.
I perform a search, get results, find the message I was after. How do I locate this message within my (relatively) complex folder and subfolder structure?
How do I improve performance while doing pull, push and delete from Azure Storage Queue
I have a MAC Pro from 2011 currently running MAC OS 10.9.5.  This weekend I cloned the MAC HD drive to a new SSD drive for improved performance.  The clone was completed successfully with no errors.  After the clone completed I successfull restarted my sy
How can i perform a search on my external hard drive on my mac pro os x 10.9.2 ?
The google feeling lucky app from the address bar is not working, a program called vshare performs a search instead and I am unable to restore the original function. please help
Improving performance of scripts in a PDF form
Optimizing Bea Weblogic Server to improve performance
Can't perform wildcard searches
Improving Performance

Times ten to improve performance for search results in Oracle eBS

-0001-11-30

Hi , We have various search scenarios in our ERP implementaion using Oracle Apps eBS, for example searching for an item . Oracle apps does provide item search but performance is not great. We have about 30 million items and hence to improve the perfo

A64 Tweaker and Improving Performance

2015-10-11

I noticed a little utility called "A64 Tweaker" being mentioned in an increasing number of posts, so I decided to track down a copy and try it out...basically, it's a memory tweaking tool, and it actually is possible to get a decent (though not

Using Lightroom and Aperture, will a new ATI 5770/5870 vs. GT 120 improve performance?

-0001-11-30

I have a MP (2009, 3.3 Nehalem Quad and 16GB RAM) and wanted to improve performance in APERTURE (see clock wheel processing all the time) with edits, also using Lightroom, and sometimes CS5.  Anyone with experience that can say upgrading from the GT1

How to improve performance on SD document with over 1000 line items

-0001-11-30

Dear experts, A lot of our SD document contains 1500 to 5000 line items. Saving a simple change of one line item description would take 5 minutes (with or without pricing considerations). We are on ECC 5.0. Does anyone know of an existing snote or wa

How to improve performance on MacBook Pro 10.5.8?

-0001-11-30

I have a MacBook Pro running 10.5.8 that has become way too slow. It hesitates between key strokes and response and is slow to search and navigate websites. I just checked and there are no updates due. What can I do to improve performance?Please read

FI-CA events to improve performance

2015-10-11

Hello experts, Does anybody use the FI-CA events to improve the extraction performance for datasources 0FC_OP_01 and 0FC_CI_01 (open and cleared items)? It seems that this specific exits associated to BW events have been developped especially to impr

How to preload sound into memory to improve performance?

2015-10-11

Hello all I have an application where it needs to play 4 different short wave files on some events. The wave files are small (less then 1 sec each) so they can be preloaded into memory. But I don't really know how to do that.. This is my current code

How to improve performance of MediaPlayer?

2015-10-11

I tried to use the MediaPlayer with a On2 VP6 flv movie. Showing a video with a resolution of 1024x768 works. Showing a video with a resolution of 1280x720 and a average bitrate of 1700 kb/s leads to a delay of the video signal behind the audio signa

How to improve performance when there are many TextBlocks in ItemsControl items?

2015-10-11

   Hi,    I'm trying to find a way to improve performance for a situation when there is an ItemsControl using UI and Data virtualization and each item on that control has 36 TextBlocks. Basically the item is a single string. There are so many TextBlo

How to improve Performance of the Statements.

2015-10-11

Hi, I am using Oracle 10g. My problem is when i am Execute & fetch the records from the database it is taking so much time. I have created Statistics also but no use. Now what i have to do to improve the Performance of the SELECT, INSERT, UPDATE, DEL

I perform a search, get results, find the message I was after. How do I locate this message within my (relatively) complex folder and subfolder structure?

2015-10-11

Hi, I use structured subfolder system to keep my emails organized (hundreds and hundreds of folders). When I perform a search, get a list of results and within this list I find the email I was after, HOW do I locate the message? In other words, how c

How do I improve performance while doing pull, push and delete from Azure Storage Queue

2015-10-11

        Hi, I am working on a distributed application with Azure Storage Queue for message queuing. queue will be used by multiple clients across the clock and thus it is expected that it would be heavily loaded most on the time in usage. business ca

I have a MAC Pro from 2011 currently running MAC OS 10.9.5.  This weekend I cloned the MAC HD drive to a new SSD drive for improved performance.  The clone was completed successfully with no errors.  After the clone completed I successfull restarted my sy

2015-10-11

I have a MAC Pro from 2011 currently running MAC OS 10.9.5.  This weekend I cloned the MAC HD drive to a new SSD drive for improved performance.  The clone was completed successfully with no errors.  After the clone completed I successfully restarted

How can i perform a search on my external hard drive on my mac pro os x 10.9.2 ?

2015-10-11

how can i perform a search on my external hard drive on my mac pro os x 10.9.2 ?Mac OS X 10.9.2 is 12 years newer than 9.2.x.    You need to make sure that Spotlight has indexed the external hard drive by adding it and removing it from Apple menu ->

The google feeling lucky app from the address bar is not working, a program called vshare performs a search instead and I am unable to restore the original function. please help

2015-10-11

I do not know how but vshare, has been performing a search everytime I type something in the address bar that is not a complete website i.e. facebook instead of facebook.com this is very annoying and I am unable to uninstall vshare, I have even tried

Improving performance of scripts in a PDF form

2015-10-11

Hello there.  I'm a bit new to the scripting in Acrobat and find myself with a complex form that has a number of instances (about 70)  of the following script (specific to individual fields): event.value=this.getField("Ranks").value + this.getFi

Optimizing Bea Weblogic Server to improve performance

2015-10-11

How do you optimize Bea Weblogic Server to improve performance?WebLogic Server Performance and Tuning http://edocs.bea.com/wls/docs81/perform/index.htmlRead other 3 answers

Can't perform wildcard searches

-0001-11-30

Hello world, We're using Portal 3.0.9.8.1 with Patch 1949492 installed. This is on 8.1.7.2.4 SE Database. When performing a search, cannot include wildcards. E.g. a search for 'test' returns only the exact word 'test'. It does not return 'testing','t

Improving Performance

-0001-11-30

Hi Experts, How can we improve the performance of the select with out creating an secondary index? In my select query am not using  primary fields in where condation. so i want to know that how can we improve the performance . one more thing is that