comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: quick matrix algebra question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: quick matrix algebra question [message #46858 is a reply to message #46855] Mon, 09 January 2006 13:17 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Hi Brad,

<b_gom@hotmail.com> wrote in message
news:1136835388.675373.55640@z14g2000cwz.googlegroups.com...
> I'm sure someone must have a quick solution for this problem. I have a
> color transformation that I want to apply to an RGB pixel as follows:
>
> M=fltarr(3,3)
> RGB=bytarr(3)
> ;fill RGB and M with some values
> result = transpose(M ## RGB) ;apply the transform.

To do this with consistency when there's more than one pixel, you might want
to flip things around:

IDL> m=FIndGen(3,3)
IDL> RGB=BIndGen(3)
IDL> Print,Transpose(M ## RGB)
5.00000 14.0000 23.0000
IDL> Print,RGB ## Transpose(M)
5.00000 14.0000 23.0000

Same result, but now this is extensible to a (3, n) array...

> Now, result contains the new values in the same format as RGB.
> The question is: how do I do this efficiently on an RGB image (ie a
> (3,col,row) array)? Quick, before I use a for loop!

col=40
row=50
RGB=BIndGen(3, col, row)

;; Reform RGB to (3, n)

RGB = Reform(rgb, 3, Long(col)*row, /Overwrite) ; this is fast

result = RGB ## Transpose(M) ;apply the transform.

;; Reform the arrays back to (3, col, row)

RGB = Reform(RGB, 3, col, row, /Overwrite)
result = Reform(result, 3, col, row, /Overwrite)

There you go!

Cheers,
--
-Dick

Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
[Message index]
 
Read Message
Read Message
Previous Topic: Make_array() and using arrays as subscripts
Next Topic: IDL routine to compute and plot particle trajectory given series of velocity fields

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 11:22:27 PDT 2025

Total time taken to generate the page: 1.43870 seconds