X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 22 May 2007 07:12 PM by  anon
read/write text files??
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
22 May 2007 07:12 PM
    Hi, This is fairly an easy problem that I unfortunately do not know the answer to. I find myself with the same problem several times, and don't know of an elegant way of addressing it: I have a bunch of images. 6 sets of 10 repeated images. I need to calculate the mean and variance of 1 pixel in each set and plot them. I know how to read each pixel and obtain mean and variance. The question I have is handling all these files as they are separate. I have right now, calculated my mean and variance and saved them in a separate folder as .sav file for each set. Then I am trying to find all .sav files in that folder and restore them to be able to plot them. There's the hic. Restoring does not work, and I am pretty sure, I should not be saving as .sav, but not sure how else to save and retrieve this data. Any thoughts? Thanks, rp

    Deleted User



    New Member


    Posts:
    New Member


    --
    22 May 2007 07:12 PM
    I get the impression that you are keeping a statistic for the mean and variance on each pixel coordinate in 10 "repeated images". And that you are calculating 6 such sets of statistics, because you have 6 sets of 10 repeated images. In the end, I am guessing you want a plot of two 6-element arrays for any given pixel coordinate, one showing the mean, the other showing the variance. So, assuming that you have a block of 10 images in 1 set, let's say all 360 x 360 in size, organized as a 3D image cube array, e.g. 'myimages' with dimensions of 360 x 360 x 10, then you might get your mean and variance in this way: meansArray = total(myimages, 3) / 10.0 subtractorArray = fltarr(360, 360, 10) for i = 0, 9 do subractorArray[0,0,i] = meansArray variances = abs(myimages - subtractorArray) help, variances ;VARIANCES FLOAT = Array[360, 360, 10] averageVariances = total(variances, 3) / 10.0 help, averageVariances ;AVERAGEVARIANCES FLOAT = Array[360, 360] I now assume that you are want to store 'meansArray' and 'averageVariances' in the file system on your hard drive. Using an IDL-formatted '.sav' file should be easy. The only downside to using the '.sav' file approach is if you are using the same code to process each of your 6 image cubes. In that scenario, you run the likelihood of having in each of your 6 output '.sav' files the same variable name assigned to arrays that have divergent values. If you later were in a loop that looked like this: for i = 0, 5 do restore, 'my_means_and_variances' + strtrim(i, 2) + '.sav' You would have the same two variables 'meansArray' and 'averageVariances' being overwritten during every iteration of the 6-cycle loop. However, the following approach WOULD work with '.sav' files. myMeansPlotData = fltarr(360, 360, 6) myVariancesPlotData = fltarr(360, 360, 6) for i = 0, 5 do begin restore, 'my_means_and_variances' + strtrim(i, 2) + '.sav' myMeansPlotData[0,0,i] = meansArray myVariancesPlotData[0,0,i] = averageVariances endfor In the above approach, each dataset is stored persistently as a "slice" in a new 3D array. Now, the results at any given coordinate can be easily plotted with code like: myCoord = [100, 40] plot, myMeansPlotData[myCoord[0], mycoord[1], *] James Jones
    You are not authorized to post a reply.