I have data from an image processing program that I need to piece back together. My image data are originally an array of 18 (6 x 3) wells on a microscope slide, I need to number these wells consistently so I can identify what was in each well later on. I have the approximate x and y positions (in pixels) of the wells, and I want to sort them from left to right and then top to bottom (seems simplest) and number them 1 to 18.
like this:
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 2 3 4 5 6
[2,] 7 8 9 10 11 12
[3,] 13 14 15 16 17 18
The caveats:
-Not all wells were picked up by the image processing program, so sometimes there are less than 18.
-Not all wells in the same row or column are on the exact same x or y, they seem to float around within 20-40 pixels.
-Not all images are centered on the same point or at the exact same magnification so well positions are not reliable enough to code for a range.
Example of data:
Well BBXLeft BBYTop
1 0 39 637
2 1 43 1218
3 2 596 630
4 3 610 1212
5 4 1161 633
6 5 1164 1207
7 6 1710 623
8 7 1715 1202
9 8 2267 620
10 9 2271 1199
11 10 2824 617
12 11 2845 1197
13 12 35 57
14 13 593 53
15 14 1709 45
16 15 2262 41
17 16 2820 38
Or in reproducible form from dput:
wells <- structure(list(Well = 0:16, BBXLeft = c(39L, 43L, 596L, 610L,1161L, 1164L, 1710L, 1715L, 2267L, 2271L, 2824L, 2845L, 35L, 593L, 1709L, 2262L, 2820L), BBYTop = c(637L, 1218L, 630L, 1212L, 633L, 1207L, 623L, 1202L, 620L, 1199L, 617L, 1197L, 57L, 53L, 45L, 41L, 38L)), .Names = c("Well", "BBXLeft", "BBYTop"), class = "data.frame", row.names = c(NA, -17L))
Wells are out of order from image analysis program
This example missing well #15 (or 14 if count from 0)
Ideal output would be a new column with the left-right, top-bottom well numbers (or even “battleship” coordinates)
Sorry if this is a bit of a homework question but I really don’t know how to do this efficiently without hard-coding the cutoffs. I’m using R because it’s the only language I have a grasp on and I have other code ready to go written around this problem.
The code below will help you to sort your wells according to the pixel location.
However, perhaps more importantly is the following —
These are your WellNumber labels plotted against the pixel location. Is this labeling scheme intentional, or are the well locations getting shuffled when labeling the image data?
In order to sort your data, we simply need a natural break, such as image size. In the example below I chose 500, but you can adjust as needed.