Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6913 > unrolled thread
| Started by | Peter Rodenbach <peter.rodenbach@googlemail.com> |
|---|---|
| First post | 2011-12-03 10:08 +0000 |
| Last post | 2011-12-04 07:58 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Delete close, but not identical elements in an array Peter Rodenbach <peter.rodenbach@googlemail.com> - 2011-12-03 10:08 +0000
Re: Delete close, but not identical elements in an array A Retey <awnl@gmx-topmail.de> - 2011-12-04 07:55 +0000
Re: Delete close, but not identical elements in an array A Retey <awnl@gmx-topmail.de> - 2011-12-04 07:55 +0000
Re: Delete close, but not identical elements in an array "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-04 07:56 +0000
Re: Delete close, but not identical elements in an array Ray Koopman <koopman@sfu.ca> - 2011-12-04 07:58 +0000
| From | Peter Rodenbach <peter.rodenbach@googlemail.com> |
|---|---|
| Date | 2011-12-03 10:08 +0000 |
| Subject | Delete close, but not identical elements in an array |
| Message-ID | <jbcsev$bvn$1@smc.vnet.net> |
Hi,
I have the problem that I have to indentify peaks in an 2D array. I
can do this by Ordering[] the entries in the Flatten[] list. Then I
indentify the positions of the peaks in the array and write them into
a list. An example I work on in an 512 x 512 Pixel array:
Peaks={{229,170},{119,265},{331,202},{118,264},{314,245}}
As you can see from those 5 peaks, Number 2 and 4 belong to the same
peak. As I have to count the data at that positions and compare them,
I have to get rid of the peak postions that neighbor each other, as
they actually belong to the same peak.
What I want now is: have Mathem. evaluate the positions in the list
and delete those which are +-10 pixels around any other.
So the list would look like Peaks={{229,170},{119,265},{331,202},
{314,245}} afterwards.
Thanks for the help!!
[toc] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2011-12-04 07:55 +0000 |
| Message-ID | <jbf91f$l3o$1@smc.vnet.net> |
| In reply to | #6913 |
Hi,
> I have the problem that I have to indentify peaks in an 2D array. I
> can do this by Ordering[] the entries in the Flatten[] list. Then I
> indentify the positions of the peaks in the array and write them into
> a list. An example I work on in an 512 x 512 Pixel array:
>
> Peaks={{229,170},{119,265},{331,202},{118,264},{314,245}}
>
> As you can see from those 5 peaks, Number 2 and 4 belong to the same
> peak. As I have to count the data at that positions and compare them,
> I have to get rid of the peak postions that neighbor each other, as
> they actually belong to the same peak.
>
> What I want now is: have Mathem. evaluate the positions in the list
> and delete those which are +-10 pixels around any other.
> So the list would look like Peaks={{229,170},{119,265},{331,202},
> {314,245}} afterwards.
I think this is what you want:
DeleteDuplicates[peaks, Norm[#1 - #2] <= 10 &]
hth,
albert
[toc] | [prev] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2011-12-04 07:55 +0000 |
| Message-ID | <jbf92e$l43$1@smc.vnet.net> |
| In reply to | #6913 |
Am 03.12.2011 11:08, schrieb Peter Rodenbach:
> Hi,
>
> I have the problem that I have to indentify peaks in an 2D array. I
> can do this by Ordering[] the entries in the Flatten[] list. Then I
> indentify the positions of the peaks in the array and write them into
> a list. An example I work on in an 512 x 512 Pixel array:
>
> Peaks={{229,170},{119,265},{331,202},{118,264},{314,245}}
>
> As you can see from those 5 peaks, Number 2 and 4 belong to the same
> peak. As I have to count the data at that positions and compare them,
> I have to get rid of the peak postions that neighbor each other, as
> they actually belong to the same peak.
>
> What I want now is: have Mathem. evaluate the positions in the list
> and delete those which are +-10 pixels around any other.
> So the list would look like Peaks={{229,170},{119,265},{331,202},
> {314,245}} afterwards.
maybe this is even "better" than just deleting close values, depending
on what you actually do:
Mean /@ Gather[peaks, Norm[#1 - #2] <= 10 &]
hth,
albert
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-12-04 07:56 +0000 |
| Message-ID | <jbf93c$l48$1@smc.vnet.net> |
| In reply to | #6913 |
On Sat, 03 Dec 2011 10:08:31 -0000, Peter Rodenbach
<peter.rodenbach@googlemail.com> wrote:
> Hi,
>
> I have the problem that I have to indentify peaks in an 2D array. I
> can do this by Ordering[] the entries in the Flatten[] list. Then I
> indentify the positions of the peaks in the array and write them into
> a list. An example I work on in an 512 x 512 Pixel array:
>
> Peaks={{229,170},{119,265},{331,202},{118,264},{314,245}}
>
> As you can see from those 5 peaks, Number 2 and 4 belong to the same
> peak. As I have to count the data at that positions and compare them,
> I have to get rid of the peak postions that neighbor each other, as
> they actually belong to the same peak.
>
> What I want now is: have Mathem. evaluate the positions in the list
> and delete those which are +-10 pixels around any other.
> So the list would look like Peaks={{229,170},{119,265},{331,202},
> {314,245}} afterwards.
>
> Thanks for the help!!
>
I guess I would suggest something along these lines (with a couple of
extra duplicates added to your example for expository purposes):
In[1] :=
pks = {
{229, 170}, {119, 265}, {331, 202}, {118, 264}, {314, 245},
{331, 203}, {113, 268}
};
In[2] :=
(* Define our distance metric *)
nf = Nearest[
pks,
DistanceFunction -> (Boole[EuclideanDistance[##] > 10] &)
]
Out[2] =
NearestFunction[{7,2}, <>]
In[3] :=
(* Gather duplicates by peak *)
dups = Rest /@ DeleteDuplicates@Select[nf /@ pks, Length[#] > 1 &]
Out[3] =
{{{118, 264}, {113, 268}}, {{331, 203}}}
In[4] :=
(* Remove duplicates *)
DeleteCases[pks, Alternatives @@ Flatten[dups, 1]]
Out[4] =
{{229, 170}, {119, 265}, {331, 202}, {314, 245}}
[toc] | [prev] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-12-04 07:58 +0000 |
| Message-ID | <jbf976$l4o$1@smc.vnet.net> |
| In reply to | #6913 |
On Dec 3, 2:08 am, Peter Rodenbach <peter.rodenb...@googlemail.com>
wrote:
> Hi,
>
> I have the problem that I have to indentify peaks in an 2D array. I
> can do this by Ordering[] the entries in the Flatten[] list. Then I
> indentify the positions of the peaks in the array and write them into
> a list. An example I work on in an 512 x 512 Pixel array:
>
> Peaks={{229,170},{119,265},{331,202},{118,264},{314,245}}
>
> As you can see from those 5 peaks, Number 2 and 4 belong to the same
> peak. As I have to count the data at that positions and compare them,
> I have to get rid of the peak postions that neighbor each other, as
> they actually belong to the same peak.
>
> What I want now is: have Mathem. evaluate the positions in the list
> and delete those which are +-10 pixels around any other.
> So the list would look like Peaks={{229,170},{119,265},{331,202},
> {314,245}} afterwards.
>
> Thanks for the help!!
DeleteDuplicates[Peaks, Norm[#1-#2] <= 10 &]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web