X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 25 Sep 2007 11:38 AM by  anon
pixel and surrounding value
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
25 Sep 2007 11:38 AM
    rpertaub@gmail.com View profile More options Sep 25, 1:20 pm Newsgroups: comp.lang.idl-pvwave Hello, I am trying to find the intensity of a pixel and its surrounding pixels. I have a list of x and y coordinates as my points of interest. I want to find the intensity at that pixel and the ones surrounding it and obtain a mean of those 9 pixels. I want to do this for all my coordinates, so I will be using a for loop to go from one coordinate to another. Is there a quick way of reading the pixel int of adjacent pixels so my for loop is not too slow? Thanks, RP

    Deleted User



    New Member


    Posts:
    New Member


    --
    25 Sep 2007 11:38 AM
    Actually, Radha, you should not need a FOR loop at all. What you want to do is what is called a convolution, and it is performed on whole arrays in a one line call to CONVOL in IDL. Here is an example, whose behavior is easy to observe: ; Make an example 8x8 array of easy-to-add random numbers IDL> seed = 1L IDL> data = float(floor(randomu(seed, 8, 8) * 5)) IDL> print, data, FORMAT='(8D6.1)' 2.0 0.0 3.0 2.0 4.0 1.0 3.0 0.0 3.0 3.0 1.0 3.0 4.0 2.0 3.0 1.0 1.0 3.0 3.0 4.0 0.0 1.0 4.0 1.0 2.0 1.0 1.0 2.0 4.0 4.0 0.0 4.0 3.0 3.0 0.0 1.0 2.0 4.0 4.0 4.0 1.0 3.0 0.0 1.0 1.0 4.0 1.0 3.0 0.0 3.0 2.0 4.0 3.0 1.0 0.0 2.0 2.0 0.0 2.0 2.0 2.0 1.0 4.0 3.0 IDL> kernel = fltarr(3, 3) + 1./9. ; This is a 3 x 3 matrix of weights with same value .111 IDL> print, convol(data, kernel), FORMAT='(8D6.2)' 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 2.11 2.44 2.67 2.33 2.44 1.78 0.00 0.00 2.00 2.33 2.44 2.67 2.44 2.22 0.00 0.00 1.89 2.00 1.89 2.44 2.56 2.89 0.00 0.00 1.56 1.33 1.33 2.56 2.67 3.11 0.00 0.00 1.67 1.89 1.56 2.33 2.22 2.56 0.00 0.00 1.44 1.89 1.89 2.11 1.89 2.11 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 There are keywords to CONVOL that give you different choices about how the edge values of the output should be calculated ... and/or you can always merge the CONVOL output with the edges of the original data if you like. James Jones ITT Technical Support
    You are not authorized to post a reply.