How to create an Average Image from Gray Scale (8 bits) JPEG Images

I�m trying to create a mean image from 9 JPEG Images, but this mean image has lots of "noise", is distorced, and doesnt�resemble at all the original ones.
I need this mean image so I�ll correlate each of the original ones to find out the best image I�m going to choose ussing NCC (normalized cross correlation coeficient).
When I use setRGB(x,y,rgb), it returns diferent "images" according to the number of zeros, for ex.: rgb = 028028028 is different from 28028028 and from 282828. I can�t find a way to work it out.
My algorithm is the folowing:
        File f;
        double [] [] pixels = null;
        Color [] [] tempPixel = null;
        Integer [] [] byte0 = null;
        Integer [] [] byte1 = null;
        Integer [] [] byte2 = null;
        Integer [] [] byte3 = null;
     Integer [] [] tempPixels = null;
        mean = null;
        int w,h;
        fileNames = new String[numFrames];
        for (int i=1; i<numFrames; i++){
            fileName = path + "Frame#" + i + ".jpg";
            fileNames[i-1] = fileName;
        // just for getting width, height, for configuring pixels array and
        // buffered images - mean & best.
        fileName = path + "Frame#8.jpg";
        f= new File(fileName);
        try{
            temp = ImageIO.read(f);
        }catch(IOException io){ return false;}
        w = temp.getWidth();
        h = temp.getHeight();
        mean = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
     pixels = new double [w][h];
        byte0 = new Integer [w][h];
        byte1 = new Integer [w][h];
        byte2 = new Integer [w][h];
        byte3 = new Integer [w][h];
        tempPixel = new Color[w][h];
          tempPixels = new Integer[w][h];
        f=null; temp = null;
        //reset pixels values.
        for(int x = 0; x < w; x++){
            for(int y = 0; y < h; y++){
                byte0[x][y] =0;
                byte1[x][y]=0;
                byte2[x][y]=0;
                byte3[x][y] = 0;
                pixels[x][y] = 0;
        // read each file (image), and according to W & H and collects the
        // pixels values.
        for(int j=0; j<numFrames-1; j++) {
            f = new File(fileNames[j]);
            try{
                temp = ImageIO.read(f);
            }catch(IOException io){ return false;}
            if(temp!=null)
                for(int x=0 ; x< temp.getWidth(); x++){
                for(int y=0; y<temp.getHeight(); y++){
                    tempPixel[x][y] = new Color(temp.getRGB(x,y));
              pixels[x][y] = pixels[x][y] + temp.getRGB(x,y) / 16581375;
                    //BLUE
                    byte0[x][y] = byte0[x][y] + (tempPixel[x][y].getBlue());//tempPixel[x][y].getBlue(); //& 0xff;
                    //GREEN
                    byte1[x][y] = byte1[x][y] + (tempPixel[x][y].getGreen());// >>8 & 0xff;
                    //RED
                    byte2[x][y] = byte2[x][y] + (tempPixel[x][y].getRed()); //>>16 & 0xff;
                    //ALPHA
                    byte3[x][y] = byte3[x][y] + (tempPixel[x][y].getAlpha()); //>>24 & 0xff;
            f=null;
        }//end of loop for j<numFrames
        String t0, t1, t2, t3;
        for(int x=0 ; x< temp.getWidth(); x++){
            for(int y=0; y< temp.getHeight(); y++){
                 byte0[x][y] = byte0[x][y] / numFrames;
                if((byte0[x][y])<10)
                         t0= "0" + byte0[x][y].toString();
                //else if((byte0[x][y])>=10 & ((byte0[x][y])<100))
                //    t0 = "0" + byte0[x][y].toString();
                else
                    t0 = byte0[x][y].toString();
                byte1[x][y] = byte1[x][y] / numFrames;
                if((byte1[x][y])<10)
                         t1=  "0" + byte1[x][y].toString();
                //else if((byte1[x][y])>=10 & ((byte1[x][y])<100))
                //    t1= "0" + byte1[x][y].toString();
                else
                    t1 = byte1[x][y].toString();
                byte2[x][y] = byte2[x][y] / numFrames;
                if((byte2[x][y])<10)
                         t2= "0" + byte2[x][y].toString();
                //else if((byte2[x][y])>=10 & ((byte2[x][y])<100))
                //    t2 = "0" + byte2[x][y].toString();
                else
                    t2 = byte2[x][y].toString();
                byte3[x][y] = byte3[x][y] / numFrames;
                if((byte1[x][y])<10)
                    t3="0" + byte3[x][y].toString();
                else
                    t3 = byte3[x][y].toString();
                    pixels[x][y] = (pixels[x][y]/numFrames) * 16581375;
                try{
                    String rgbs = t2+t1+t0;
                    Integer rgb = Integer.valueOf(rgbs);
                          //System.out.println("Valor do rgb: " +rgb);
                    mean.setRGB(x,y,(int)pixels[x][y]);
                }catch(NumberFormatException nfe){
                    System.out.println("ERROR: Integer to STRING: "  + nfe);
                    return false;
                }// end of catch

It�s ok, I�ve already found the solution.
Thanks.

Similar Messages

  • How to create a pdf file from multiple images ?

    Dear All,
    I want to create a SINGLE page pdf file from two or more page size images that are combined to make a single page pdf. Again, this question is on pdfs that are made out of several, atleast  two color images and a black-and-white mask for one of them.
    I have such pdf files from an unknown source (the producer is edited out) whereby there are three tiff images, obtained using the well known pdfimages extractor.
    When I want to make a pdf out of tiff or png or other image formats, I right click and tell Adobe Acrobat to make a pdf.
    However, I dont know how I can give a command to select say,  three tif images and specify which is the mask for which and then join  them in a way that I get the pdf from the composite of the two color images and a mask for one of them.
    Please help me out.
    I am a little familiar with the pdf structure skeleton and when necessary, fixed xref tables in one of my favorite editors. A few years ago, I also wrote a bunch of javascripts to make some annotations and needed some automation and used some itext type libraries. However, I need your help in this problem as I am now rusty and forgot some of what I studied to solve my earlier problems. This is a new problem for me. Gentle hints from you would be very nice to help me in this problem. Please specify if necessary what manual and pages to read. in the pdfspec.
    Best Regards
    Disabled Veteran [physically handicapped]

    Hello Again.
    On Fri, May 11, 2012 at 12:20 PM, lrosenth <[email protected]> wrote:
    >
    > Re: How to create a pdf file from multiple images ?
    >
    > created by lrosenth in PDF Language and Specifications - View the full
    > discussion
    > ________________________________
    >
    > No clue who Irving is…
    >
    I was hoping to have your first name so its easy for me to address you.
    > I have no clue what OS platform, programming language, etc. you use so
    > can’t really narrow things down.
    I would gladly mention that I am working on windows platform, preferably XP.
    I can also work on linux for free products that come with it.
    >  Also, as this is an Adobe forum, we only
    > recommend Adobe products – so there may be other options that even my list
    > wouldn’t include.
    But adding other products, for the help of an adobe products user,
    even if it outside adobe, shall add greater prestige to your company
    and give impression of user-centeredness.
    > If you read ISO 32000-1:2008 (aka the PDF standard), you will find the
    > information about Images and Image Masks well described.  I didn’t think I
    > needed to repeat any of that information.
    Well, just add the few pdf stanzas since you are proficient on it and
    I am presently a little rusty as I mentioned. Just asking a little
    extra yard, not even to go an extra mile.
    > And, if you read that same document, you will see that there is NO SUCH
    > THING as a “text only PDF”.   All PDF documents are structured binary files.
    Well, ascii format or uncompressed format that is human readable. I
    know its a binary file, but human readable ascii version of it.
    I hope you can give me some stanza and various other approaches
    possible so I can select or combine things for myself. I see only a
    miniscule number of posts claiming to have written masks in this forum
    and then with no details.
    Regards
    Roger
    Message was edited by: dying veteran
    because the adobe posting system went crazy and truncated all except the first line ... dunno why

  • How to convert color image(24 bit) YUV 4:2:2 to gray scale 8 bit image

    I am using sony DFW-X700 color camera for one of vision applications.Does NI Compact Vision System(CVS) support YUV 4:2:2 format(8 bit each).I want to do gray scale processing, so i need to convert the YUV color into gray scale (8-bit) in the software(like Labview). Please suggest us how to do this conversion for better gray scale image clarity from color.

    In YUV color space, Y represents the gray scale; in RGB color space, R=G=B represents gray scale. You can simply set R=G=B=Y, to convert YUV to RGB. If the original color depth is 24 bit, then the result is 24 bit too.
    You can create gray scale color table like this:
    array size = 256;
    [0] = 0x000000;
    [1] = 0x010101;
    [2] = 0x020202;
    [255] = 0xFFFFFF;
    To convert 24 bit gray scale to 8 bit, check every pixel in 24 bit image to find the array index according to the color table, and replace the pixel with array index.
    George Zou
    http://gtoolbox.yeah.net
    George Zou
    http://webspace.webring.com/people/og/gtoolbox

  • How to create dvd/cd image using super drive in MacBook Air

    I have MacBook Air and also Apple Supper drive for the same. can u help me to find dvd/cd burrning and copy software. and also guide me "how to create dvd/cd image using super drive in MacBook Air"

    First to create a video DVD you need to use DVD authoring software like iDVD.  You can purchase it from the online Apple Store while supplies last.
    For creating a disk image use Disk Utility.
    To burn items to a CD or data DVD just insert the disc in the optical drive and drag those items onto the disc icon on the Desktop.  Then drag the disc icon to the Trash icon in the Dock which changes to a Burn icon.
    OT

  • How to Create a new column from two different result sets

    How to Create a new column from two different result sets, both the result set uses the different date dimensions.

    i got solutions for this is apply filters in column formula it self, based on the requirement.

  • How to create a new connection from SAPGUI to Test drive?

    Hi,
    I have installed Sap Netweaver Test drive on a linux virtual machine (windows host). The installation was successful and I was able to start the instance (application server and the database), yet I don't know how to create a new connection from my SAPGUI client (7.20) to this server. The static IP address of the server is 192.168.1.160.
    I entered the following values for my new connection entry
    Description: SAP Netweaver
    Application server: 192.168.1.160
    Instance number: 01
    System ID: DB2
    SAProuter: /H/192.168.1.160/S/3201/H/
    But it does not work. Any idea about the values needed  for creating a new entry?
    Thanks in advance,
    Dariyoosh

    >
    Dibya R Das wrote:
    > Why are you entering a router string? Can't you reach a box directly from your machine?
    >
    > Doesn't a ping to that host & a "telnet <host/ip address> 3201" work from your machine to the SAP System.
    >
    > Remove the router string you wont need if the above works.
    >
    > - Regards, Dibya
    Hello there,
    Thank you very much for your answer which solved my problem. In fact there was no need of providing router string.
    Kind Regards,
    Dariyoosh

  • How to create a background image for each item in a List object

    Hello.
    I am trying to create a background image that displays whenever a user posts something to a list.  For example when a user posts text it would appear in a list.  The new item in the list would contain a specific background image with the users text appearing on top of the background image.  I do not want a background image for the entire list, rather each item within the list.
    I am not sure how clear this is so I added an image below.  When a user enters text in and clicks the "post-it" button their text would appear below with the sticky note background. 
    I am not sure which list type would be best for this problem or how to create insert the image, so I am open to suggestions. 
    Thank you for your help.  Any advice or guidance will be greatly appreciated!

    Hi
    the easiest way would be with itemRenderer.
    You have to do two things:
    1. In your list declaration use a item renderer: <mx:List itemRenderer="myRenderer"/>
    2. create a flex component myRenderer that will be the single item. This can be a canvas with a background image and a text field on it.
    When you add a new item to the list, a new myRenderer item will be created and the data property will be passed to it. So you have to put "data" in your textField.
    If you need more help try looking at Tour de Flex samples, they're pretty easy.
    Andrei

  • How to create a PAR file from EAR file

    Hi,
       I have created an Web Dynpro Application . When i deploy it in Remote J2EE Engine, it will deploy as EAR file. It then runs as normal Web Application in Web browser. My requirement is to create an iView for my Web dynpro appn in EP. That is possible only by creating a PAR file. so How to create an PAR file from EAR in NWDS(NetWeaver Developer Studio).
    How to access the EAR file in NWDS or J2EE ?
    Thanks in Advance ,
    By
    Saravanan

    Hi,
    To create a iview,
    log on to portal, New iView and select SAP webdynpro iview.
    It will ask for namespace which is usually , local/Project Name
    and application name is the name of the application.
    We dont have to create par file for this requirement

  • How to create an XML document from a String.

    Can anyone help,
         In the Microsoft XML Document DOM there is a load function load(string) which will create an XML document, but now we are switching to Java and I do not know how to create and XML document from a string, this string �xml document� is passed to my program from a webservice and I need to read several xml elements form it in a web server.
    This string is a well formatted XML document:
    <?xml version="1.0" encoding="UTF-8"?>
    <Countries NumberOfRecords="1" LanguageID="en-us">
         <Country>
              <CountryCode>AU</CountryCode>
              <CountryName>AUSTRALIA</CountryName>
         </Country>
    </Countries>

    Thanks PC!
    I made it work using:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    factory.setIgnoringComments(true); // We want to ignore comments
    // Now use the factory to create a DOM parser
    DocumentBuilder parser = factory.newDocumentBuilder();
    //TransformThisStringBuffer is a string buffer wich contain the 'XML document (String)'
    InputStream in = new ByteArrayInputStream(TransformThisStringBuffer.toString().getBytes());
    // Parse the InputStream and build the document
    Document document = parser.parse(in);
    But which one is faster InputSource or InputStream, were would you put the "new InputSource(new StringReader(yourString))" in the above code?

  • How to create a .DLL file from a .C file ?

    Hi everybody
    I'm looking for a method how to create a .DLL file from a .C file .That Dll file will be used to perform a board to measure voice quality accoding to the international standard named PESQ (perceptual evaluation of speech qualty) P.862.
    Can anyone help to start dealing with Dlls and give some advices to avoid errors ?
    thx
    Attachments:
    source.zip ‏37 KB

    Hi sinaps,
    You mention that you want to create a DLL from a .C file. Just to clarify, are you using C (.c file) or C++ (.cpp) to write your code?
    Also, if you are using C++, are you using Visual Studio? (The reason I ask is because this forum is geared towards Measurement Studio, which is an add on to Microsoft Visual Studio).
    That being said,
    If you are using C: National Instruments provides an ANSI C Application Development Environment called LabWindows/CVI which makes building dlls a snap. It has templates for DLLs and you can build them either as stdcall or cdecl dlls.
    Developer Zone Tutorial: Building a DLL with LabWindows/CVI 8.5 for use with LabVIEW 8.5
    If you are using Visual C++: Look at the link that Al provided earlier.
    MSDN: Walkthrough: Creating and Using a Dynamic Link Library
    If you aren't using CVI or Visual Studio, then really the best bet is to do a google search for "Create C DLL" or post or a forum for the appropriate environment that you are using.
    Thanks!
    Message Edited by Jervin_J on 03-14-2009 02:02 PM
    Jervin Justin
    NI TestStand Product Manager

  • How to Create an XML document from XSQL servlet which follows a particular DTD struct

    how to Create an XML document from XSQL servlet which follows a particular DTD structure.Could anyone send me a sample code for this.

    You'll need to associate an XSLT transformation with your XSQL page that transforms the canonical result into your DTD-valid format.
    For example, given an XSQL page like:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="rss.xsl" ?>
    <xsql:query max-rows="3" connection="demo" xmlns:xsql="urn:oracle-xsql">
    select title,id,description,url,to_char(timestamp,'Mon DD') timestamp
    from site_entry
    order by id desc
    </xsql:query>and an "rss.xsl" stylesheet that looks like this:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" doctype-system="rss-0.91.dtd"/>
    <xsl:template match="/">
    <xsl:for-each select="ROWSET/ROW">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    <xsl:for-each select="ITEM">
    <item>
    <title><xsl:value-of select="TITLE"/></title>
    <link><xsl:value-of select="URL"/></link>
    <description><xsl:value-of select="DESCRIPTION"/></description>
    </item>
    </xsl:for-each>
    </channel>
    </rss>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>You produce DTD-valid output against the rss-0.91.dtd DTD that looks like:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE rss SYSTEM "rss-0.91.dtd">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>

  • How to create a standby redolog from rac to non rac ??

    Hi,
    How to create a standby redolog from rac to non rac DR setup..???
    in rac we can create with specifying thread number for each instances..... but this will be replicating to standby ....so how this will act/create on single DR??
    pls help

    854393 wrote:
    Thanks Shivanandha,
    (maximum number of logfiles for each thread + 1) * maximum number of threads
    Using this equation reduces the likelihood that the primary instance's log writer (LGWR) process will be blocked because a standby redo log file cannot be allocated on the standby database. For example, if the primary database has 2 log files for each thread and 2 threads, then 6 standby redo log file groups are needed on the standby database.In maximum performance mode you can keep same number of redo logs but having one more redo log member for each thread is recommended and mandtory for other protection modes.
    How to create a standby redolog from rac to non rac DR setup..???
    in rac we can create with specifying thread number for each instances..... but this will be replicating to standby ....so how this will act/create on single DR??pls help
    Yes, even your DR is RAC or non-RAC, you must have both threads, because each instance information exist on own thread, So to perform redo transition from both the instances, you must have both standby redo log threads even though if it is non an RAC DR.
    Hope This helps.

  • How to create a boot disc from Lion pre installed into my Macbook Pro 2011 ?

    Hi guys,
    I want to know how to create a boot disc from Lion pre installed into my New Macbook Pro ?
    I want to re-install the Lion from zero. When I bougth it I´ve used the Migrant assitance and now I want to re-install the Lion. How can I do it ?
    thanks.

    Read this about creating a lion recovery on an external drive or USB stick.
    http://support.apple.com/kb/HT4848
    /Dennis

  • How to create a p7c format from a pem or der or cer

    Hi,
    Anybody knows how to create a p7c format from a pem or der or cer.
    I have checked the URL http://edocs.bea.com/wlibc/docs70/admin/cvcerts.html and
    other sites but didn't find anything useful.
    Thanks & Regards,
    Subodh

    On Windows double click the der or cer certificate. This should open it in the
    Certificate viewer.
    Open the Details tab, click on the Copy to File button and select pkcs #7 format.
    Pavel.
    "Subodh" <[email protected]> wrote:
    >
    Hi,
    Anybody knows how to create a p7c format from a pem or der or cer.
    I have checked the URL http://edocs.bea.com/wlibc/docs70/admin/cvcerts.html
    and
    other sites but didn't find anything useful.
    Thanks & Regards,
    Subodh

  • How to create A/R Invoice from draft

    Hi,
              How to create A/R Invoice from documnet draft using DIAPI.
    Thanks,
    P.Suresh Kumar

    Hi Suresh Kumar,
    You may check this as a reference: Re: Problems while saving the tax values in a Draft Document to AP Invoice
    Thanks,
    Gordon

Maybe you are looking for