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

Home » Public Forums » archive » Re: Function BYTSCL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Function BYTSCL [message #24627] Tue, 10 April 2001 18:20
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
Steffen Kernchen wrote:
>
>> Of course you can do by hand something similar what bytscl does:
>>
>> lets say your array is 'a'
>>
>> minA=min(a,MAX=maxA)
>> a=a-minA
>> a=byte(float(a)/maxA*255)
>>
>> (2nd line is 'optional')
>
> when I use the 2nd line, then there is no picture displayed!
> if I don�t write this line I see a pic, that is only brighter. There is no
> more contrast. :(
>
>> but why you should not use bytarr?
>> Only point I can guess is that you have 8bit color and dont want to
>> use all colors?
>
> no, it�s an exercise, so that we learn, what BYTSCL does.
>
> I 've a pic and I read it with READ_BMP to get an array. that array I have
> to transform to get a better contrast.
> but unfortunately without using BYTSCL... :(
>
> cheers,
>
> steffen
Sorry, 2nd and 3rd line should read:

a=a-minA
a=byte(float(a)/(maxA-minA)*255)
*****
then it should work.
Its almost the same as bytscl with its default settings.
But strange that you don't see any picture with the old 2nd line.
Probably you just see a very dark one.
Cheers,
marc
Re: Function BYTSCL [message #24629 is a reply to message #24627] Tue, 10 April 2001 16:43 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
David Fanning (davidf@dfanning.com) writes:

> What BYTSCL does is take the data, finds the minimum
> and maximum of the data, then linearly maps the min
> and max to 0 and 255. This is the scaling function.
> Then, it adds a translation to the scaled vector, so
> that the minimum value is set to zero. Then, it converts
> the whole thing to BYTE type.

I was driving home from the bookstore trying to think
of an excuse to give my wife for why I was 45 minutes
late picking up my son from school, when it suddenly
occurred to me that this problem is *exactly* like
trying to convert Fahrenheit to Celsius degrees!

Funny how and when these things come to you, isn't it. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Function BYTSCL [message #24631 is a reply to message #24629] Tue, 10 April 2001 10:18 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Jaco van Gorkom (j.c.van.gorkom@fz-juelich.de) writes:

> Be sure to drop by, David. I'll take you out for
> some German beers. And I have got this colour flashing
> problem, by the way :-)

I'm trying to put on a sober countenance for my son,
who came to Germany last August and immediately fell
under the pernicious influence of the dark side and
their wicked (but delicious) ways. The drinking age
in the US is 21, but I'm afraid that is going to be
a hard genie to get back in the bottle (literally). :-(

And, truth be told, I think I'm way too old and
out of shape to keep up.

But we could talk about that color flashing problem
over tea, if you like. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Function BYTSCL [message #24632 is a reply to message #24631] Tue, 10 April 2001 09:37 Go to previous message
Jaco van Gorkom is currently offline  Jaco van Gorkom
Messages: 97
Registered: November 2000
Member
David Fanning wrote:
>
> Jaco van Gorkom (j.c.van.gorkom@fz-juelich.de) writes:
>
>> So I guess it does make for some good
>> programming exercise...
>
> Must be a European thing. :-)
>
> But I'm off to Germany later this week, so I'll check
> it out.

Be sure to drop by, David. I'll take you out for
some German beers. And I have got this colour flashing
problem, by the way :-)

Jaco

PS: I'm just using a German news server at the moment.
I am really in the Netherlands, enjoying a two-day sabbatical,
kind of. Be welcome to come and try some Dutch beer:)
Re: Function BYTSCL [message #24633 is a reply to message #24632] Tue, 10 April 2001 08:10 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Steffen Kernchen (steffen.kernchen@student.uni-magdeburg.de) writes:

> no, it�s an exercise, so that we learn, what BYTSCL does.
>
> I 've a pic and I read it with READ_BMP to get an array. that array I have
> to transform to get a better contrast.
> but unfortunately without using BYTSCL... :(

Oh, well, then.

What BYTSCL does is take the data, finds the minimum
and maximum of the data, then linearly maps the min
and max to 0 and 255. This is the scaling function.
Then, it adds a translation to the scaled vector, so
that the minimum value is set to zero. Then, it converts
the whole thing to BYTE type.

You are right, the whole thing can be done in 4-5 lines. :-)

Cheers,

David

P.S. Let's just say that if you poked around in the
on-line libraries for a couple of minutes, you would
probably find something that did this sort of thing
for you. :-)

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Function BYTSCL [message #24634 is a reply to message #24633] Tue, 10 April 2001 07:44 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Steffen Kernchen wrote:
> what function(s) can I use instead of BYTSCL?
> I have an array and I want to transform it to get a better contrast.
> But I should NOT use BYTSCL.... :(

It sounds like you want to do something other than selecting the minimum
and maximum array values for the scaling range used in BYTSCL. How about
trying histogram clipping?

(1) Compute a histogram for the image at N (say N=100) intervals between
the minimum and maximum array values.

(2) From the low end of the histogram, find the histogram bin where X
percent (say X=2) of the total number of array elements (pixels) lie to
the *left* of the current bin. The data value for this bin becomes the
minimum of the scaling range. Perform a similar search from the high end
of the histogram to obtain the maximum of the scaling range.

(3) Now use BYTSCL with the derived scaling range to create a contrast
enhanced image.

Other functions that will be useful in this exercise are HISTOGRAM and
TOTAL.

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
Re: Function BYTSCL [message #24635 is a reply to message #24634] Tue, 10 April 2001 07:42 Go to previous message
Steffen Kernchen is currently offline  Steffen Kernchen
Messages: 4
Registered: April 2001
Junior Member
> Of course you can do by hand something similar what bytscl does:
>
> lets say your array is 'a'
>
> minA=min(a,MAX=maxA)
> a=a-minA
> a=byte(float(a)/maxA*255)
>
> (2nd line is 'optional')

when I use the 2nd line, then there is no picture displayed!
if I don�t write this line I see a pic, that is only brighter. There is no
more contrast. :(

> but why you should not use bytarr?
> Only point I can guess is that you have 8bit color and dont want to
> use all colors?

no, it�s an exercise, so that we learn, what BYTSCL does.

I 've a pic and I read it with READ_BMP to get an array. that array I have
to transform to get a better contrast.
but unfortunately without using BYTSCL... :(


cheers,

steffen
Re: Function BYTSCL [message #24636 is a reply to message #24635] Tue, 10 April 2001 07:30 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Jaco van Gorkom (j.c.van.gorkom@fz-juelich.de) writes:

> So I guess it does make for some good
> programming exercise...

Must be a European thing. :-)

But I'm off to Germany later this week, so I'll check
it out.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Function BYTSCL [message #24637 is a reply to message #24636] Tue, 10 April 2001 07:18 Go to previous message
Jaco van Gorkom is currently offline  Jaco van Gorkom
Messages: 97
Registered: November 2000
Member
Steffen Kernchen wrote:
..
>> You are going to have to give us a clue why you
>> should NOT use BYSCL. Is this a religious preference?
>
> *g* no, it is a condition for a given exercise.
> it�s for my first program, i�ve to write for a new lecture at my
> university.
> so the answer for my question should be quite simple. just 3 or 4 lines...

If you would want to use BYTSCL, but you are not allowed to use
the built-in function, then you can just code up your own scaling.
To scale (= multiply) an array by a certain factor (e.g.,
MyFactor=2):
MyArray = MyArray * MyFactor
To substract (or add) any offsets:
MyArray = MyArray - MyOffset
To limit (clip) the array values to a certain range:
MyArray = MyMinRange < MyArray < MyMaxRange
MIN() or MAX() can be used to find the original range of the
array. You could determine the factor and offset you want to use
from them.

It should be possible to code up something sensible in just a few
lines. Beware of possible overflow, if you are in byte type then
things can easily get >255. So I guess it does make for some good
programming exercise...

cheers,
Jaco
Re: Function BYTSCL [message #24641 is a reply to message #24637] Tue, 10 April 2001 06:55 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Steffen Kernchen (steffen.kernchen@student.uni-magdeburg.de) writes:

> *g* no, it is a condition for a given exercise.
> it�s for my first program, i�ve to write for a new lecture at my
> university.
> so the answer for my question should be quite simple. just 3 or 4 lines...
>
> do you have an idea?

No. Not really. :-)

This seems like a strange course. "Contrast" is a visual
property. It pertains to how something is *displayed*,
which always involves bytes sooner or later.

If you want to do something to improve contrast to an
array, I suppose you can multiply the array by some
non-linear spreading function, then "normalize" it
into the range 0 to 255, if you prefer not to use the
term "byte scale". (I guess something like
this is done with histogram equalization, come to think
of it.) Perhaps we should just wait for JD to provide
the HISTOGRAM solution. (He isn't the guest lecturer,
is he?)

Cheers,

David

P.S. Let's just say I'm glad I'm not taking an IDL
programming class. :-(

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Function BYTSCL [message #24644 is a reply to message #24641] Tue, 10 April 2001 03:08 Go to previous message
marc schellens[1] is currently offline  marc schellens[1]
Messages: 183
Registered: January 2000
Senior Member
Steffen Kernchen wrote:
>
> Hi...
>
> I�m just starting with IDL, so here is my first question: ;-)
>
> what function(s) can I use instead of BYTSCL?
> I have an array and I want to transform it to get a better contrast.
> But I should NOT use BYTSCL.... :(
>
> bye
>
> steffen

Of course you can do by hand something similar what bytscl does:

lets say your array is 'a'

minA=min(a,MAX=maxA)
a=a-minA
a=byte(float(a)/maxA*255)

(2nd line is 'optional')
but why you should not use bytarr?
Only point I can guess is that you have 8bit color and dont want to
use all colors?
In that case you have to find the different used colors in a:

h=histogram(a)
wN0=where(h ne 0,nW)

replace them:

for i=0,nW-1 do begin
wI=where(a eq wN0[i])
a[wI]=i
endfor

and modify the color table to assign the remaining values to colors
0..255:

TVLCT, R, G, B, /GET

R[0:nW-1]=byte(float(indgen(nW))/nW*255)
G[0:nW-1]=byte(float(indgen(nW))/nW*255)
B[0:nW-1]=byte(float(indgen(nW))/nW*255)

TVLCT, R, G, B

then you can plot your image.

Cheers,
marc
Re: Function BYTSCL [message #24645 is a reply to message #24644] Tue, 10 April 2001 03:51 Go to previous message
Steffen Kernchen is currently offline  Steffen Kernchen
Messages: 4
Registered: April 2001
Junior Member
thx for your answer!


> You are going to have to give us a clue why you
> should NOT use BYSCL. Is this a religious preference?

*g* no, it is a condition for a given exercise.
it�s for my first program, i�ve to write for a new lecture at my
university.
so the answer for my question should be quite simple. just 3 or 4 lines...

do you have an idea?



steffen
Re: Function BYTSCL [message #24648 is a reply to message #24644] Tue, 10 April 2001 03:17 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Steffen Kernchen (steffen.kernchen@student.uni-magdeburg.de) writes:

> I�m just starting with IDL, so here is my first question: ;-)
>
> what function(s) can I use instead of BYTSCL?
> I have an array and I want to transform it to get a better contrast.
> But I should NOT use BYTSCL.... :(

You are going to have to give us a clue why you
should NOT use BYSCL. Is this a religious preference?

It is hard to imagine how you are going to improve
*visual* contrast without byte scaling something!

If you want to improve the contrast in your array
locally, you might try a program like XSTRETCH:

http://www.dfanning.com/programs/xstretch.pro

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: sec : U Re: Dual head displays
Next Topic: Re: Error on shutdown of widget !@$%

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

Current Time: Wed Oct 08 15:10:12 PDT 2025

Total time taken to generate the page: 0.01435 seconds