Re: Difficult Label_region question [message #59980] |
Thu, 24 April 2008 05:32  |
moxament
Messages: 26 Registered: April 2008
|
Junior Member |
|
|
On 24 Απρ, 02:33, Gaurav <selfishgau...@gmail.com> wrote:
> But, of course, you will benefit greatly by reading about the WHERE
> function. It will cut a lot of your processing time if you are running
> loops (as it appears to be from the subscripts in your code).
>
> Cheers
> Gaurav
Thank you for the help. Your suggestions are good, but I think you did
not understand what I wanted exactly. I want to use the label_region
in order the imnew to contain three segments. The first segment
contains pixels from the first channel, the second segment contain
pixels from the second channel, and the third segment contains pixels
from the third channel. Having used the label_region I can tv the
imnew by giving one pseudo color to each segment (I do not know how to
do that as will).
And using the label_region will let me further process each segment
separately after that.
I hope it is clear now. I am beginner in IDL and I do not know many
things. so your help is appreciated.
Thank you very much
MD
|
|
|
|
Re: Difficult Label_region question [message #59983 is a reply to message #59982] |
Wed, 23 April 2008 23:11   |
Gaurav
Messages: 50 Registered: January 2007
|
Member |
|
|
You definitely do not need LABEL_REGION as far as I understand your
problem. As far as I get it you want to create a new 2D array whose
each element will identify whether the highest DN value for that
location lies in Red, Green or the Blue channel.
If I am right so far, then you are assigning wrongly in your code. In
your example if, say, the blue DN value of a pixel is greater than the
Red and Green value for that pixel, you are assigning the value of
Blue DN value in the imnew array. However, what you should do is to
just assign the lable signifying 'blue' for that pixel. If I assume 1
for Blue, 2 for Green and 3 for Red, I would write the same code as
if im[i, j, 0] qt im[i, j, 1] and im[i, j, 0] qt im[i, j,
2] then imnew[i, j] = 1
So, in the end your imnew array will contain only values 1,2 or 3
which when displayed as a pseudo color image will give you the desired
output.
If, however, you wish to preserve the gray level along with it being
displayed as RGB, you could consider converting your imnew to be a
Integer type of array and than assign the values of the array as:
if im[i, j, 0] qt im[i, j, 1] and im[i, j, 0] qt im[i, j,
2] then imnew[i, j] = 0 * 255 + im[i, j, 0] ; or similarly 1*255 +
im[i, j, 1] and so on
This way if a pixel is of blue color, its value will lie between 0-255
in the output array, if it is green it will be between 256-511 and so
on. But I am not sure how you will display this as your output image
in RGB.
In any case, LABEL_REGION figures nowhere, so stop looking in the
wrong place.
Cheers,
Gaurav
|
|
|
Re: Difficult Label_region question [message #59984 is a reply to message #59983] |
Wed, 23 April 2008 21:33   |
Jonathan Dursi
Messages: 9 Registered: November 2006
|
Junior Member |
|
|
On Apr 23, 10:21 pm, moxam...@gmail.com wrote:
> I have an image/array im[300, 300, 3] and I want to compare the the
> value of of each element in each channel and write the bigger in a new
> array imnew[300,300] keeping the information from which channel is the
> element value in the new array.
It's not clear to me that label_region is really what you need
here.
The following seems more along those lines:
;; just get some random data
img = randomu(1,300,300,3)
;; find the maximum value along the colour axis,
;; along with where that maximum resides -- as a
;; 1d index into the entire img array
imgnew = max(img,ms,DIMENSION=3)
;; reform that 1d array of 1d indicies first into a 1d array
;; of 3d indicies into the array pointing where the maximum
;; is; put that back into the 300x300 shape of the initial
;; image, and take the only index we need, the color index
imgcolor = reform((reform(array_indices(img,ms),3,300,300))[2,*,*])
So now imgnew[xi,yi] has the maximum channel intensity
for pixel (xi,yi) and imgcolor[xi,yi] has the channel number
(0,1, or 2) of that maximum.
If you only want to do this for plotting purposes, there may
be some easier/faster way to go about it, but this seems like
the most direct way to get the asked-for info...
Jonathan
--
Jonathan Dursi
ljdursi@gmail.com
|
|
|
Re: Difficult Label_region question [message #60058 is a reply to message #59980] |
Fri, 25 April 2008 00:09  |
Gaurav
Messages: 50 Registered: January 2007
|
Member |
|
|
>> I want to use the label_region
>> in order the imnew to contain three segments. The first segment
>> contains pixels from the first channel, the second segment contain
>> pixels from the second channel, and the third segment contains pixels
>> from the third channel.
Even in that case, LABEL_REGION is not the function to use.
LABEL_REGION is used in a binary image when there are sompe pixels
clumped togetther. Suppose you had a binary satellite image in which
all the water bodies where colored with the value 255 while all rest
was 0. If there were 5 separate waterbodies, you could use
LABEL_REGION to identify the number of waterbodies, number them and to
find the pixels belonging to each waterbody. Ergo, WHERE would still
be the function that would come into use for you.
You should use WHERE function with the INDICES keyword to get the
locations that satisfy your value, something like
index_blue = WHERE(BLUE GT GREEN AND BLUE GT RED)
where BLUE GREEN and RED contain the three bands of your data.
Similarly you can get the elements for index_green and index_red.
These three variables will contain the "segments" you are looking for
and you can process them together.
Hope it helps...
Gaurav
|
|
|
Re: Difficult Label_region question [message #60068 is a reply to message #59980] |
Thu, 24 April 2008 10:55  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On Apr 24, 6:32 am, moxam...@gmail.com wrote:
> On 24 Áðñ, 02:33, Gaurav <selfishgau...@gmail.com> wrote:
>
>> But, of course, you will benefit greatly by reading about the WHERE
>> function. It will cut a lot of your processing time if you are running
>> loops (as it appears to be from the subscripts in your code).
>
>> Cheers
>> Gaurav
>
> Thank you for the help. Your suggestions are good, but I think you did
> not understand what I wanted exactly. I want to use the label_region
> in order the imnew to contain three segments. The first segment
> contains pixels from the first channel, the second segment contain
> pixels from the second channel, and the third segment contains pixels
> from the third channel. Having used the label_region I can tv the
> imnew by giving one pseudo color to each segment (I do not know how to
> do that as will).
>
Not sure what you want, but is this close?
m = max(im, ind, dimension=3)
band = ind / (300 * 300)
device, decomposed=0
tvlct, 255, 0, 0, 0
tvlct, 0, 255, 0, 1
tvlct, 0, 0, 255, 2
tv, band
Mike
--
Tech-X Corporation
Software Developer II
|
|
|