Local minima

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

Local minima

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
joleenf
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Local minima

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
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: Local minima

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.
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

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
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

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
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: Local minima

Hi Michele...

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.

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

Re: Local minima

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

Bye

Michele
joleenf
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Local minima

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
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: Local minima

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 neededeles, 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.
micder
Posts: 10
Joined: Wed Jun 19, 2013 1:00 pm

Re: Local minima

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