mardi 1 mars 2016

Complex loop, output to new file using r- can I make a GUI?

The data below are from a single line drawn across a CT image. I am able to output the data from each line based on values at each pixel. In the image, there are horizontal bands (light and dark) based on density. Each light or dark band is made up of a number of pixels (this number is not the same every time because the organism that generates these bands grows at different rates at different times). There is also no pattern to the number of pixels per band.

What I am trying to do is this:

  1. Manually record which pixel number is the start and end of each band

  2. Use a script to determine the mean density of all pixels within that range, along with the sum of the extension and calcification columns over that range (cumext doesn't really matter).

  3. Put these calculated values in a new data frame with the same column headings

  4. Automate a process whereby after finishing one band, the script will move on to the next band (with new start and end pixels).

A subset of the data is posted below. I'm out of my depth on this one. I've come up with a simple way to calculate values for one band, but have yet to discover how to repeat the process and output the calculated values into a data frame.

Here is some example code:

a=read.csv(file="yorcf26s_1-14_3.csv")
head(a)
str(a)
a

#Subset of 1 band. Need to make this run a bunch of times in a row and move down the core
b=subset(a, Pixel>=1 & Pixel<=30)
mean(b$Density)
sum(b$Extension)
sum(b$Calcification)


Pixel Density   Extension   CumExt  Calcification
1   1.216841393 0.025218838 0.025218838 0.030687326
2   1.253195807 0.025218838 0.050437677 0.031604142
3   1.28363206  0.025218838 0.075656515 0.032371709
4   1.304768346 0.025218838 0.100875353 0.032904742
5   1.367331755 0.025218838 0.126094192 0.034482519
6   1.508522151 0.025218838 0.15131303  0.038043176
7   1.64041258  0.025218838 0.176531868 0.0413693
8   1.673385188 0.025218838 0.201750707 0.042200831
9   1.698748732 0.025218838 0.226969545 0.04284047
10  1.698748732 0.025218838 0.252188384 0.04284047
11  1.700439635 0.025218838 0.277407222 0.042883112
12  1.688603314 0.025218838 0.30262606  0.042584614
13  1.664930673 0.025218838 0.327844899 0.041987618
14  1.660703416 0.025218838 0.353063737 0.041881011
15  1.648021644 0.025218838 0.378282575 0.041561191
16  1.651403449 0.025218838 0.403501414 0.041646477
17  1.651403449 0.025218838 0.428720252 0.041646477
18  1.688603314 0.025218838 0.45393909  0.042584614
19  1.664085222 0.025218838 0.479157929 0.041966296
20  1.632803517 0.025218838 0.504376767 0.041177408
21  1.626039905 0.025218838 0.529595605 0.041006838
22  1.607439973 0.025218838 0.554814444 0.040537769
23  1.587149138 0.025218838 0.580033282 0.040026058
24  1.550794724 0.025218838 0.60525212  0.039109241
25  1.511058505 0.025218838 0.630470959 0.03810714
26  1.487385864 0.025218838 0.655689797 0.037510144
27  1.493304024 0.025218838 0.680908636 0.037659393
28  1.528812986 0.025218838 0.706127474 0.038554888
29  1.615894488 0.025218838 0.731346312 0.040750982
30  1.642948935 0.025218838 0.756565151 0.041433264
31  1.64041258  0.025218838 0.781783989 0.0413693
32  1.624349002 0.025218838 0.807002827 0.040964195
33  1.627730808 0.025218838 0.832221666 0.04104948
34  1.632803517 0.025218838 0.857440504 0.041177408
35  1.609130876 0.025218838 0.882659342 0.040580411
36  1.587149138 0.025218838 0.907878181 0.040026058
37  1.57108556  0.025218838 0.933097019 0.039620953
38  1.556712885 0.025218838 0.958315857 0.039258491
39  1.559249239 0.025218838 0.983534696 0.039322455
40  1.556712885 0.025218838 1.008753534 0.039258491

Aucun commentaire:

Enregistrer un commentaire