Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ij import IJ, ImagePlus
- from ij.process import FloatProcessor
- from array import zeros
- def box_maker(radius):
- box = []
- for i in range(2*radius):
- y = []
- for j in range(2*radius):
- y.append(0)
- box.append(y)
- box[4][4] = 1
- box[4][3] = 1
- box[3][4] = 1
- box[5][4] = 1
- box[4][5] = 1
- return box
- def config_img(imp):
- pix = list(imp.getProcessor().getPixels())
- w = imp.getWidth()
- h = imp.getHeight()
- new_im = []
- for i in range(h):
- y = []
- for j in range(w):
- y.append(pix[i*h+j])
- new_im.append(y)
- return new_im
- def protein_find(pix, y, x, boxcent, boxedge):
- centsum = 0.0
- for boxx, boxy in boxcent:
- centsum += pix[y + boxy][x + boxx]
- centavg = centsum/5
- edgesum = 0.0
- for boxx, boxy in boxedge:
- edgesum += pix[y + boxy][x + boxx]
- edgeavg = edgesum/36
- if centavg/edgeavg > 2.0:
- return x, y
- else:
- return 0, 0
- radius = 5
- box = box_maker(radius)
- imp = IJ.getImage()
- h = imp.getHeight()
- w = imp.getWidth()
- IJ.run("16-bit")
- #------------------------------------------------
- #Adaptive Histogram Equalisation
- blocksize = '127'
- histogram_bins = '256'
- maximum_slope = '3'
- mask = "*None*"
- fast = True
- process_as_composite = True
- parameters = "blocksize =" + blocksize + " histogram=" + histogram_bins + \
- " maximum=" + maximum_slope + " mask=" + mask
- if fast:
- parameters += " fast_(less_accurate)"
- IJ.run( "Enhance Local Contrast (CLAHE)", parameters )
- #------------------------------------------------
- IJ.run("Subtract Background...", "rolling=10")
- new_pix = config_img(imp)
- boxcent = [[4, 4], [3, 4], [4, 3], [5, 4], [4,5]]
- boxedge = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9],
- [1, 0], [1, 9], [2, 0], [2, 9], [3, 0], [3, 9], [4, 0], [4, 9], [5, 0], [5, 9], [6, 0], [6, 9],
- [7, 0], [7, 9], [8, 0], [8, 9], [9, 0], [9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7],
- [9, 8], [9, 9]]
- prots = []
- counts = 0
- for i in range(h):
- for j in range(w):
- if (i > 0 + radius) and (i < h - 2*radius) and (j > 0 + radius) and (j < w - 2*radius):
- outx, outy = protein_find(new_pix, i, j, boxcent, boxedge)
- if outx != 0:
- prots.append([i, j])
- counts +=1
- pix2 = zeros('f', w * h)
- for i in range(len(prots)):
- x, y = prots[i]
- pix2[x*h+y] = 1.0
- fp = FloatProcessor(imp.getWidth(), imp.getHeight(), pix2, None)
- imp3 = ImagePlus("prots", fp)
- imp3.show()
- print counts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement