def generate_intensity_weighted_curvature(curvature_overlay, curvature_profiles, intensity_channel_imp, colormap_string): """Generate intensity-weighted curvature image""" w = intensity_channel_imp.getWidth() h = intensity_channel_imp.getHeight() curv_impRGB = curvature_overlay.clone() IJ.run(curv_impRGB, colormap_string, "") IJ.run(curv_impRGB, "RGB Color", "") int_imp16 = intensity_channel_imp.clone() base_impRGB = intensity_channel_imp.clone() IJ.run(base_impRGB, "Grays", "") IJ.run(base_impRGB, "RGB Color", "") maxes = [] for fridx in range(0, int_imp16.getNFrames()): int_imp16.setPositionWithoutUpdate(1, 1, fridx + 1) maxes.append(int_imp16.getStatistics(Measurements.MIN_MAX).max) mx = float(max(maxes)) for idx, profile in enumerate(curvature_profiles): print("Frame = " + str(idx)) curv_impRGB.setPosition(idx + 1) curvCP = curv_impRGB.getProcessor() base_impRGB.setPosition(idx + 1) baseCP = base_impRGB.getProcessor() int_imp16.setPosition(idx + 1) for chidx in range(0, 3): c = ['r', 'g', 'b'] print("Image channel = " + c[chidx]) baseBP = ByteProcessor(base_impRGB.getWidth(), base_impRGB.getHeight()) curvBP = ByteProcessor(base_impRGB.getWidth(), base_impRGB.getHeight()) baseBP = baseCP.getChannel(chidx, baseBP) curvBP = curvCP.getChannel(chidx, curvBP) for ((x, y), c) in profile: # ensure that no rounding issues cause pixels to fall outside image... if x > (w - 1): x = w - 1 if y > (h - 1): y = h - 1 if x < 0: x = 0 if y < 0: y = 0 x = int(round(x)) y = int(round(y)) baseBP.putPixelValue( x, y, int( curvBP.getPixel(x, y) * float(int_imp16.getPixel(x, y)[0]) / mx)) #baseBP.putPixelValue(x, y, int(curvBP.getPixel(x,y))); baseCP.setChannel(chidx, baseBP) base_impRGB.setProcessor(baseCP) base_impRGB.setTitle("Merged") base_impRGB.show() curv_impRGB.show() pause_for_debug()
def hyst(ima, T1, T2): la = ima.getWidth() ha = ima.getHeight() res = ByteProcessor(la, ha) for x in xrange(la): for y in xrange(ha): pix = ima.getPixelValue(x, y) if pix >= T1: res.putPixel(x, y, 255) elif pix >= T2: res.putPixel(x, y, 128) change = True while (change): change = False for x in xrange(1, la - 1): for y in xrange(1, ha - 1): if (res.getPixelValue(x, y) == 255): if (res.getPixelValue(x + 1, y) == 128): change = True res.putPixelValue(x + 1, y, 255) if (res.getPixelValue(x - 1, y) == 128): change = True res.putPixelValue(x - 1, y, 255) if (res.getPixelValue(x, y + 1) == 128): change = True res.putPixelValue(x, y + 1, 255) if (res.getPixelValue(x, y - 1) == 128): change = True res.putPixelValue(x, y - 1, 255) if (res.getPixelValue(x + 1, y + 1) == 128): change = True res.putPixelValue(x + 1, y + 1, 255) if (res.getPixelValue(x - 1, y - 1) == 128): change = True res.putPixelValue(x - 1, y - 1, 255) if (res.getPixelValue(x - 1, y + 1) == 128): change = True res.putPixelValue(x - 1, y + 1, 255) if (res.getPixelValue(x + 1, y - 1) == 128): change = True res.putPixelValue(x + 1, y - 1, 255) if (change): for x in xrange(la - 2, 0, -1): for y in xrange(ha - 2, 0, -1): if (res.getPixelValue(x, y) == 255): if (res.getPixelValue(x + 1, y) == 128): change = True res.putPixelValue(x + 1, y, 255) if (res.getPixelValue(x - 1, y) == 128): change = True res.putPixelValue(x - 1, y, 255) if (res.getPixelValue(x, y + 1) == 128): change = True res.putPixelValue(x, y + 1, 255) if (res.getPixelValue(x, y - 1) == 128): change = True res.putPixelValue(x, y - 1, 255) if (res.getPixelValue(x + 1, y + 1) == 128): change = True res.putPixelValue(x + 1, y + 1, 255) if (res.getPixelValue(x - 1, y - 1) == 128): change = True res.putPixelValue(x - 1, y - 1, 255) if (res.getPixelValue(x - 1, y + 1) == 128): change = True res.putPixelValue(x - 1, y + 1, 255) if (res.getPixelValue(x + 1, y - 1) == 128): change = True res.putPixelValue(x + 1, y - 1, 255) for x in xrange(la): for y in xrange(ha): if (res.getPixelValue(x, y) == 128): res.putPixelValue(x, y, 0) return res