Create an image from a 1D array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Create an image from a 1D array

YuriGagarine
Hi all,

I have a 1D array that I'd like to transform it into an image. It is a NxM array its elements are included between 0 and 255.
What I'd like to do is, maybe thanks to a function which accept as inputs an 1D array, the height and the width of the output image.

The equivalent in Matlab are the functions reshape and imagesc.

PS: Sorry for my english.
Reply | Threaded
Open this post in threaded view
|

Re: Create an image from a 1D array

George Patterson
Hi,
If you need a macro function the below is an example which can do what you
want.  Depending on how your 1D array was generated, you may have to modify
the loops.  As written, the function below assumes the 1D array contains
the pixel values starting at the upper left and set pixels left to right.
Best,
George

function generateImageFrom1DArray(Array1D,imageWidth,imageHeight){
newImage("Untitled","8-bit",imageWidth,imageHeight,1);
image1=getImageID();
for(i=0;i<imageHeight;i++){
for(j=0;j<imageWidth;j++){
setPixel(j,i,Array1D[(i*imageWidth)+j]);
}
}
return image1;
}




On Wed, Feb 19, 2014 at 8:55 AM, YuriGagarine <[hidden email]> wrote:

> Hi all,
>
> I have a 1D array that I'd like to transform it into an image. It is a NxM
> array its elements are included between 0 and 255.
> What I'd like to do is, maybe thanks to a function which accept as inputs
> an
> 1D array, the height and the width of the output image.
>
> The equivalent in Matlab are the functions */reshape /*and */imagesc/*.
>
> PS: Sorry for my english.
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Create-an-image-from-a-1D-array-tp5006579.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Create an image from a 1D array

YuriGagarine
Thanks a lot ! You're a life saver :p