Local minima

How do I...?
User avatar
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Local minima

Post by micder »

Hi everyone,
I need to find all the local minima within an image and get the neighbors of each one within a given radius. Is it possible to do this?

Thanks a lot

Michele
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Local minima

Post by joleenf »

In a given radius, will this be defined by a physical distance (km) or by a given pixel range from the minima? What type of data? Is this in a satellite image or model data? What is a local minima? Is it defined by the entire field or sectors?

Thanks,
Joleen
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: Local minima

Post by tomw »

To follow up on Joleen's questions, I would also ask what the results should look like? (For example, just a list of the line,element location of the local minimums, plus the values of the neighboring pixels within the given radius, etc.)

This would be a good candidate for a small Jython function that you invoke using a "Formula" and pass in the image (?). If the output is not displayable, you can easily just write it to a file.
User avatar
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

Post by micder »

Hi,
thanks for the response and sorry for my "too light" question. I think to use the function on satellite images (MSG) and the distance is in pixel. The local minima could be referred to the temperature (but not only) and it is the point where there is a value lower than its neighbors. The result could be a polygon which encompasses the region of the minima and/or the element location of the local minimums, plus the values of the neighboring pixels within the given radius.

Hope to have been more clear.

Bye

Michele
User avatar
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

Post by micder »

In order to better explain what I have in my mind, please, take a look to this matlab function:

https://www.mathworks.com/help/images/r ... edmin.html

Bye
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: Local minima

Post by tomw »

Hi Michele...

Joleen and I talked about this and what follows came from that conversation.

Presently, there is no built-in function to locate a "local minimum" (or maximum). We think your best approach is to write a small Jython script to scan through the data and locate these. This would also give you the opportunity to create whatever output you want -- you had mentioned polygons, but since there is no way to display those [except through the "drawing tools"], you would probably want to just write them to a file for whatever later processing you need to do. (If, on the other hand, you simply wanted to identify the points, you could create an "image" that contained just 0s and 1s -- with, for example, the "1" values meant "local minimum".)

To get you started, you need to first get the 2D array of values from the Data object. If you read the data via ADDE, then the image likely has a form (time -> ((element, line)->data). In other cases, this is just ( (element,line)->data).

It is most convenient in situations like this to work directly with a 2D array, so you can use the JNumeric "reshape()" method to do this. Here is an example:

Code: Select all

def localmin(image):
  import Numeric as np;
  if getDomainDimension(image) == 1:
    ds = getDomainSizes(image[0]);
    a = np.reshape(image[0], [ds[1],ds[0]]);
  else:
    ds = getDomainSizes(image);
    a = np.reshape(image, [ds[1], ds[0]]);
  ...
  ...

the result in variable "a" is a 2D "array", dimensioned as [lines, elements], which you can then use to locate the pixels. We also suggest looking at the documentation for the JPythonMethods class, since it contains many useful routines.
http://www.ssec.wisc.edu/visad-docs/javadoc/visad/python/JPythonMethods.html

Hope this helps get you started...
User avatar
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

Post by micder »

Hi Tom,
thanks a lot for your help: I'll try to implement the functionality and I'll let you know.

Bye

Michele
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Local minima

Post by joleenf »

Michele,

After more discussions here, we were wondering if you wanted to track convective storms? If this is the case, this forum post may be of some use to you

viewtopic.php?f=27&t=1046&hilit=Lakshmanan&start=20

The mask function(s) in jpython methods is very useful for finding regions which meet certain criteria.

Joleen
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: Local minima

Post by tomw »

I should also clarify one thing. The "data object" that contains the satellite pixel data also contains much metadata, which is why I suggested extracting the values and using them as a 2D array in Numeric. Often times, satellite data is read into a data object that has a shape of [time][pixels] -- even if there is only one "time". The "pixels" are stored as a 1D array.

The underlying data object code does allow you to access pixel values directly, but since it is a 1D array, you would have to compute your own indexing. For example:

Code: Select all

a = selectData()[0]   // get the first "time", if needed
eles, lines = getDomainSizes(a)   // [elements, lines]
print a[100*eles + 120]  // show the value at the point (100,120)  (line, element)
a[100*eles + 120] = 200  // set the value at this point to "200"


In this way, you do not have to use Numeric to reference elements of the "data array" inside the data object -- but you would have to your own indexing. I hope this helps clarify.
User avatar
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

Post by micder »

Hi all,
thanks a lot for your support. I applied the mask function and it seems to work well. Now I'm trying to implement a my own filter in order to retrieve other information.

Bye

Michele
Post Reply