Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
sort an image

Subject: sort an image

From: Twilighter

Date: 10 Jul, 2011 08:53:07

Message: 1 of 8

Hi

i need to take the absolute value of an image and sort it.

but before doing that i need to store the sign of each value and the indexes to later restore the image again

how can i do that?

Subject: sort an image

From: Bruno Luong

Date: 10 Jul, 2011 09:18:09

Message: 2 of 8

Many way to achieve what you want.

help sign
help ops
help lt
help gt
help le
help ge

Bruno

Subject: sort an image

From: Twilighter

Date: 10 Jul, 2011 10:17:10

Message: 3 of 8

thank you for ur reply,
the first one has already solved the sign problem
but i dunno how those other operators will help me in my task

can u elaborate further?

Subject: sort an image

From: Bruno Luong

Date: 10 Jul, 2011 10:48:09

Message: 4 of 8

"Twilighter " <mscmatlab@gmail.com> wrote in message <ivbu75$pl5$1@newscl01ah.mathworks.com>...
> thank you for ur reply,
> the first one has already solved the sign problem
> but i dunno how those other operators will help me in my task
>
> can u elaborate further?

Sure, try:

img>=0

Bruno

Subject: sort an image

From: Twilighter

Date: 10 Jul, 2011 10:54:09

Message: 5 of 8

how that will help me in storing the index of the sorted pixels ??

i knew about the sign saving thanx
sign operator just works fine ....

Subject: sort an image

From: Bruno Luong

Date: 10 Jul, 2011 10:58:09

Message: 6 of 8

"Twilighter " <mscmatlab@gmail.com> wrote in message <ivc0ch$16p$1@newscl01ah.mathworks.com>...
> how that will help me in storing the index of the sorted pixels ??

help sort

It will describe there, take a look at the second output argument.

Bruno

Subject: sort an image

From: Twilighter

Date: 11 Jul, 2011 10:51:10

Message: 7 of 8

W=imread('Image.jpg');

[SWrow,swrowIndex]=sort(W,1,'ascend');
[SW,swcolIndex]=sort(SWrow,2,'ascend');
%imshow(SW,[]);

trying to restore back the original image
i tried to use the sorted indexes but my logic is wrong
it gave me the same sorted image

reverseCol = SW(swcolIndex);
reverseRow=reverseCol(swrowIndex);

how can i restore it back?

thank you for ur help

Subject: sort an image

From: Bruno Luong

Date: 11 Jul, 2011 14:39:09

Message: 8 of 8

"Twilighter " <mscmatlab@gmail.com> wrote in message <ivekiu$i9i$1@newscl01ah.mathworks.com>...
> W=imread('Image.jpg');
>
> [SWrow,swrowIndex]=sort(W,1,'ascend');
> [SW,swcolIndex]=sort(SWrow,2,'ascend');
> %imshow(SW,[]);

The sequential cascade sorting in both dimensions do not seem a normal way of processing to me, and I wonder what you want too achieve with those commands?

Anyway here a back indexing for a single sort on array, up to you to adapt when the dimension are different:

% Data
A = rand(3)

[m n] = size(A);
[B is] = sort(A,1);

%% method 1, indexed on lhs, for-loop
% Construct A from B
A2 = zeros([m n]);
for j=1:n
    A2(is(:,j),j) = B(:,j);
end
A2 % % should be equal to A

%% method 2, indexes on rhs, vectorized
% Construct back index
[I J] = ndgrid(1:m,1:n);
K(sub2ind([m n],is,J)) = I;
K = sub2ind([m n],K,J);

A3 = B(K) % should be equal to A

% Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us