Re: Convert 3D to 1D, apply fuction then convert back to 3D [message #71431] |
Mon, 21 June 2010 05:15  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Jun 20, 8:58 pm, Mat <m...@waikato.ac.nz> wrote:
> On Jun 21, 12:21 pm, pp <pp.pente...@gmail.com> wrote:
>
>> On Jun 20, 9:06 pm, Mat <m...@waikato.ac.nz> wrote:
>
>>> The results are three water quality parameters. Actually it does not
>>> matter whether they are within one result or three separate results.
>
>> That still says nothing to answer your question. You called a function
>> that used a (5,nx*xy) array and returned a 3-element array. We do not
>> know how those 3 numbers relate to the 5*nx*ny values in the array, or
>> what you were intending to get that also was supposed to have 5*nx*ny
>> elements.
>
> No the function used the "imageR" from above which is a floating 1D 5
> element array (reformed from a 5 band 3d image (satellite reflectance)
> and returned a 3-element array(water quality). The function is complex
> and not my code so I'm not in a position to post it sorry. So for each
> pixel in the original tiff I want the water quality (three parameters)
> in an image format. I hope this helps.
>
> I think it is simpler if somebody posts a code to convert an
> image(5,nx*xy) to 1D, then convert it back to the original image. I
> think I could fill in the gaps.
I don't think your function is giving you what you think. You are
giving it a 2D [5,N] element array, and it is returning a 1D [3]
element array. From your question, I think you're expecting either
a [3,N] element array or a [3,5,N] element array - i.e. each of those
three values for either every pixel, or every pixel-band combination.
-Jeremy.
|
|
|
Re: Convert 3D to 1D, apply fuction then convert back to 3D [message #71433 is a reply to message #71431] |
Sun, 20 June 2010 18:14   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Jun 20, 9:58 pm, Mat <m...@waikato.ac.nz> wrote:
> No the function used the "imageR" from above which is a floating 1D 5
> element array (reformed from a 5 band 3d image (satellite reflectance)
> and returned a 3-element array(water quality). The function is complex
> and not my code so I'm not in a position to post it sorry. So for each
> pixel in the original tiff I want the water quality (three parameters)
> in an image format. I hope this helps.
imageR as you wrote above is 2D (5,npix), not 1D.
Now I think what you mean is that you have a 5-channel image (a
(5,nx,ny) array), where you want to apply some function that takes
each of the 5 bands for each pixel, and returns 3 values for each,
which you want to put into a 3-channel image (3,nx,ny). If that is the
case, this does not indicate any need for reforming, it could be done
with something like
result=dblarr(3,nx,ny)
for i=0,ny-1 do for j=0,nx-1 do
result[*,j,i]=some_function(image[*,j,i])
> I think it is simpler if somebody posts a code to convert an
> image(5,nx*xy) to 1D, then convert it back to the original image. I
> think I could fill in the gaps.
I do not think you need to do it, but if you want to, it would be
image1d=reform(image2d,5L*nx*ny)
then, to get it back,
image2d=reform(image1d,5,nx,ny)
|
|
|
Re: Convert 3D to 1D, apply fuction then convert back to 3D [message #71435 is a reply to message #71433] |
Sun, 20 June 2010 17:58   |
Mat
Messages: 14 Registered: December 2009
|
Junior Member |
|
|
On Jun 21, 12:21 pm, pp <pp.pente...@gmail.com> wrote:
> On Jun 20, 9:06 pm, Mat <m...@waikato.ac.nz> wrote:
>
>> The results are three water quality parameters. Actually it does not
>> matter whether they are within one result or three separate results.
>
> That still says nothing to answer your question. You called a function
> that used a (5,nx*xy) array and returned a 3-element array. We do not
> know how those 3 numbers relate to the 5*nx*ny values in the array, or
> what you were intending to get that also was supposed to have 5*nx*ny
> elements.
No the function used the "imageR" from above which is a floating 1D 5
element array (reformed from a 5 band 3d image (satellite reflectance)
and returned a 3-element array(water quality). The function is complex
and not my code so I'm not in a position to post it sorry. So for each
pixel in the original tiff I want the water quality (three parameters)
in an image format. I hope this helps.
I think it is simpler if somebody posts a code to convert an
image(5,nx*xy) to 1D, then convert it back to the original image. I
think I could fill in the gaps.
|
|
|
|
Re: Convert 3D to 1D, apply fuction then convert back to 3D [message #71437 is a reply to message #71436] |
Sun, 20 June 2010 17:06   |
Mat
Messages: 14 Registered: December 2009
|
Junior Member |
|
|
On Jun 21, 11:15 am, pp <pp.pente...@gmail.com> wrote:
> On Jun 20, 7:58 pm, Mat <m...@waikato.ac.nz> wrote:
>
>
>
>
>
>> I am converting a image (5 bands) to 1D using reform. I then apply a
>> function to this data and get a double "Array[3]"result. How do I then
>> convert this result back into the origional image dimensions? eg:
>
>> image= READ_IMAGE('test.tif')
>> imagesize = SIZE(image, /DIMENSIONS)
>> nx=imagesize[1]
>> ny=imagesize[2]
>> npix = nx*ny
>> coords_2d = array_indices([nx,ny], lindgen(npix), /dimen)
>> imageR= REFORM(image,5,npix)
>
>> I then apply a function to this data and get a return in the form of:
>
>> IDL> help, ret3
>> RET3 DOUBLE = Array[3]
>
>> I'm struggling to covert this back to a 3D image. Any ideas?
>
> You are getting a result that is 1D (a 3-element vector). You can
> change it from its 1 dimension to 3, with a reform(ret3,1,1,3), but it
> would still have only 3 elements, not the original 5,nx,ny you want.
>
> You need to think about what those 3 values represent with relation to
> you image and what you were looking for, which we cannot guess just
> from that description.- Hide quoted text -
>
> - Show quoted text -
The results are three water quality parameters. Actually it does not
matter whether they are within one result or three separate results.
|
|
|
Re: Convert 3D to 1D, apply fuction then convert back to 3D [message #71438 is a reply to message #71437] |
Sun, 20 June 2010 16:15   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Jun 20, 7:58 pm, Mat <m...@waikato.ac.nz> wrote:
> I am converting a image (5 bands) to 1D using reform. I then apply a
> function to this data and get a double "Array[3]"result. How do I then
> convert this result back into the origional image dimensions? eg:
>
> image= READ_IMAGE('test.tif')
> imagesize = SIZE(image, /DIMENSIONS)
> nx=imagesize[1]
> ny=imagesize[2]
> npix = nx*ny
> coords_2d = array_indices([nx,ny], lindgen(npix), /dimen)
> imageR= REFORM(image,5,npix)
>
> I then apply a function to this data and get a return in the form of:
>
> IDL> help, ret3
> RET3 DOUBLE = Array[3]
>
> I'm struggling to covert this back to a 3D image. Any ideas?
You are getting a result that is 1D (a 3-element vector). You can
change it from its 1 dimension to 3, with a reform(ret3,1,1,3), but it
would still have only 3 elements, not the original 5,nx,ny you want.
You need to think about what those 3 values represent with relation to
you image and what you were looking for, which we cannot guess just
from that description.
|
|
|
Re: Convert 3D to 1D, apply fuction then convert back to 3D [message #71510 is a reply to message #71431] |
Mon, 21 June 2010 15:55  |
Mat
Messages: 14 Registered: December 2009
|
Junior Member |
|
|
On Jun 22, 12:15 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Jun 20, 8:58 pm, Mat <m...@waikato.ac.nz> wrote:
>
>
>
>
>
>> On Jun 21, 12:21 pm, pp <pp.pente...@gmail.com> wrote:
>
>>> On Jun 20, 9:06 pm, Mat <m...@waikato.ac.nz> wrote:
>
>>>> The results are three water quality parameters. Actually it does not
>>>> matter whether they are within one result or three separate results.
>
>>> That still says nothing to answer your question. You called a function
>>> that used a (5,nx*xy) array and returned a 3-element array. We do not
>>> know how those 3 numbers relate to the 5*nx*ny values in the array, or
>>> what you were intending to get that also was supposed to have 5*nx*ny
>>> elements.
>
>> No the function used the "imageR" from above which is a floating 1D 5
>> element array (reformed from a 5 band 3d image (satellite reflectance)
>> and returned a 3-element array(water quality). The function is complex
>> and not my code so I'm not in a position to post it sorry. So for each
>> pixel in the original tiff I want the water quality (three parameters)
>> in an image format. I hope this helps.
>
>> I think it is simpler if somebody posts a code to convert an
>> image(5,nx*xy) to 1D, then convert it back to the original image. I
>> think I could fill in the gaps.
>
> I don't think your function is giving you what you think. You are
> giving it a 2D [5,N] element array, and it is returning a 1D [3]
> element array. From your question, I think you're expecting either
> a [3,N] element array or a [3,5,N] element array - i.e. each of those
> three values for either every pixel, or every pixel-band combination.
>
> -Jeremy.- Hide quoted text -
>
> - Show quoted text -
Thanks PP you have solved my problem. Thanks for your input Jeremy yes
I think the array dimensions were confusing me!
|
|
|