COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Need help re: Lexicographic sorting on a Image

• Email
• Follow

```Hi, I am working on My ME project and need help re: Lexicographic sorting on an image, i need to read a image and then lexicographically sort the gray values and also store the index position , but i dont understand how it is to be done

for eg.

Matrix

1      2       4       5     6

10    3       21     51     91

32    43     22    12      11

45     33     11    23     55

87    44     22    88     99

what should be the output of the above matrix if i sort it lexicographically
```
 0

See related articles to this posting

```Have you looked at the sort() and find() functions?  I think that
should do it.
```
 0

```Thanks

But i am trying to use sortrows function in a loop startin with first column till nth and sort each column in ascending order but with order of the previous column

> Have you looked at the sort() and find() functions?  I think that
> should do it.
```
 0

```Well explain what lexicographic sorting is, for a 2D matrix, first,
and then we can tell you how to achieve that.

Why do you want to do this anyway?  Is there a real-world need for
some reason, or is it just a mental puzzle/brainteaser.

What is an "ME project"?  Is that like a Masters of Science graduate
degree majoring in engineering or something?
```
 0

```I am doing Masters of Engineering in Computers , My project topic is Copy-move forgery Detection In which an Image is divided into blocks and then these blocks are converted to a array , then most of the research papers on copy-move states that after getting this array u need to lexicographically sort the elements which helps reduce the number of comparisons in the array

Eg.

Consider the following image

1      2     3     4
5       6     7     8
11     55    1   2
45   1       5    6

Now i divide it into 2X2 Block

so i get the first block as

1    2
5    6

2nd block as

3  4
7   8

and so on

Now i convert these blocks in to an array as

1     2      5    6
3     4      7     8
11  55    45     1
1    2      5       6

Now i have to lexicographically sort the above array i dont know what does that mean?????????????

> Well explain what lexicographic sorting is, for a 2D matrix, first,
> and then we can tell you how to achieve that.
>
> Why do you want to do this anyway?  Is there a real-world need for
> some reason, or is it just a mental puzzle/brainteaser.
>
> What is an "ME project"?  Is that like a Masters of Science graduate
> degree majoring in engineering or something?
```
 0

```Can you explain how you got rows 3 and 4 of the output?  They seem to
have been reshaped into 1x4 blocks while the first two rows were 2x2
blocks.
```
 0

``` 1       2        3          4

5      6         7          8

1       2         6          7

5       6         9           1

Now Convert this above matrix in to a array of size  4X4

where 1st row will have the elements from the first 2X2 Block

1      2       5      6
3      4       7      8
1      2       5      6
6      7       9      1

An array considering non overlapping blocks of size (2X2)

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a6a2154e-cfb1-4fdb-8771-756aaba4aeeb@f8g2000yqd.googlegroups.com>...
> Can you explain how you got rows 3 and 4 of the output?  They seem to
> have been reshaped into 1x4 blocks while the first two rows were 2x2
> blocks.
```
 0

```Well of course we can think of some code to handle this case (just as
I'm sure you can), but I'm not sure what elements go where for higher
dimensions.  Could you also give an example for a 6 by 6 matrix or a
10 by 10 matrix?
```
 0

```ImageAnalyst <imageanalyst@mailinator.com> wrote in message <650a8138-e16c-4608-b391-d1e08ee7903b@v17g2000yqv.googlegroups.com>...
> Well of course we can think of some code to handle this case (just as
> I'm sure you can), but I'm not sure what elements go where for higher
> dimensions.  Could you also give an example for a 6 by 6 matrix or a
> 10 by 10 matrix?

Try this code... It is basically sorting the matrix entries in to lexicographically order.
%1  2  3  4
%5  6  7  8
%11 55 1  2
%45 1  5  6
index = 1;
A = [1 2 3 4;5 6 7 8;11 5 1 2;45 1 5 6]
B = zeros(4,4);
for i = 1:2:4
for j = 1:2:4
C = A(i:i+1,j:j+1)'
reshape(C,1,4)
B(index,:) = reshape(C,1,4)
index = index +1;
end
end
B
%1     2      5    6
%3     4      7    8
%11    55     45   1
%1     2      5    6
[B index] = sortrows(B)
%     1     2     5     6
%     1     2     5     6
%     3     4     7     8
%    11     5    45     1
```
 0