def test_hdx_rgb_roundtrip(self):
     from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
     img_rgb = self.img_rgb
     conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
                           rgb_from_hdx)
     with expected_warnings(['precision loss']):
         assert_equal(img_as_ubyte(conv), img_rgb)
 def test_hdx_rgb_roundtrip(self):
     from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
     img_rgb = self.img_rgb
     conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
                           rgb_from_hdx)
     with expected_warnings('precision loss'):
         assert_equal(img_as_ubyte(conv), img_rgb)
def color_deconvolution(img, sep_matrix, comb_matrix, component_idx):
    separated = separate_stains(img, sep_matrix)

    stains = np.zeros_like(separated)
    stains[:, :, component_idx] = separated[:, :, component_idx]

    combined = combine_stains(stains, comb_matrix)

    return _convert(combined, img.dtype)
示例#4
0
 def test_bro_rgb_roundtrip_float(self, channel_axis):
     from skimage.color.colorconv import bro_from_rgb, rgb_from_bro
     img_in = self.img_stains
     img_in = np.moveaxis(img_in, source=-1, destination=channel_axis)
     img_out = combine_stains(img_in,
                              rgb_from_bro,
                              channel_axis=channel_axis)
     img_out = separate_stains(img_out,
                               bro_from_rgb,
                               channel_axis=channel_axis)
     assert_array_almost_equal(img_out, img_in)
示例#5
0
 def test_hdx_rgb_roundtrip_float(self):
     from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
     img_rgb = img_as_float(self.img_rgb)
     conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
                           rgb_from_hdx)
     assert_array_almost_equal(conv, img_rgb)
示例#6
0
 def test_hdx_rgb_roundtrip(self):
     from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
     img_rgb = self.img_rgb
     conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
                           rgb_from_hdx)
     assert_equal(img_as_ubyte(conv), img_rgb)
示例#7
0
 def test_hdx_rgb_roundtrip(self):
     from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
     img_rgb = img_as_float(self.img_rgb)
     conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
                           rgb_from_hdx)
     assert_array_almost_equal(conv, img_rgb)
示例#8
0
 def test_hdx_rgb_roundtrip(self):
     from skimage.color.colorconv import hdx_from_rgb, rgb_from_hdx
     img_rgb = self.img_rgb
     conv = combine_stains(separate_stains(img_rgb, hdx_from_rgb),
                           rgb_from_hdx)
     assert_equal(img_as_ubyte(conv), img_rgb)
        x[...] = x/source_mean
        x[...] = x * target_mean

        #x[...] = x/source_stat_vector[0,0]
        #x[...] = x * target_stat_vector[0,0]

    return source_array

normalized_source_Hema = normalize_mapping(source_Hema_Gray_Array, np.mean(source_Hema_Gray_Array), np.mean(target_Hema_Gray_Array))
normalized_source_red = normalize_mapping(source_red_Gray_Array, np.mean(source_red_Gray_Array), np.mean(target_red_Gray_Array))
normalized_source_DAB = normalize_mapping(source_DAB_Gray_Array, np.mean(source_DAB_Gray_Array), np.mean(source_DAB_Gray_Array))


normalized_ihc_hrd = np.dstack((normalized_source_Hema, normalized_source_red, normalized_source_DAB))

normalized_ihc_rgb = combine_stains(normalized_ihc_hrd, rgb_from_hrd)


#Plot images
fig, axes = plt.subplots(2, 2, figsize=(12, 11))
#ax0 = axes.ravel()
ax0, ax1,  ax2, ax3 = axes.ravel()

ax0.imshow(source_ihc_rgb, cmap=plt.cm.gray, interpolation='nearest')
ax0.set_title("Original source")

ax1.imshow(target_ihc_rgb, cmap=plt.cm.gray, interpolation='nearest')
ax1.set_title("original target")

ax2.imshow(normalized_ihc_rgb, cmap=plt.cm.gray)
ax2.set_title("normalized ")
示例#10
0
plt.plot(exposure.histogram(e)[1], exposure.histogram(e)[0])

# <codecell>

io.imshow(filter.threshold_adaptive(e, 301, offset=0.025))

# <codecell>

io.imshow(A)

# <codecell>

from skimage import data
ihc = data.immunohistochemistry()
ihc_hdx = color.separate_stains(ihc, color.hdx_from_rgb)
ihc_rgb = color.combine_stains(ihc_hdx, color.rgb_from_hdx)

io.imshow(ihc_hdx[:,:,0])

# <codecell>

print [[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]
io.imshow(color.separate_stains(A, 
    np.linalg.inv([[0.644211, 0.716556, 0.266844], [0.092789, 0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]))[:, :, 2])



# <codecell>

qstain = np.array([[.26451728, .5205347, .81183386], [.9199094, .29797825, .25489032], [.28947765, .80015373, .5253158]])
qfrompaper = np.array([[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.75919851748933231, 0.085468001712004443, 0.92121791197468583]])
示例#11
0
 def test_bro_rgb_roundtrip(self):
     from skimage.color.colorconv import bro_from_rgb, rgb_from_bro
     img_in = img_as_ubyte(self.img_stains)
     img_out = combine_stains(img_in, rgb_from_bro)
     img_out = separate_stains(img_out, bro_from_rgb)
     assert_equal(img_as_ubyte(img_out), img_in)
 def test_bro_rgb_roundtrip_float(self):
     from skimage.color.colorconv import bro_from_rgb, rgb_from_bro
     img_in = self.img_stains
     img_out = combine_stains(img_in, rgb_from_bro)
     img_out = separate_stains(img_out, bro_from_rgb)
     assert_array_almost_equal(img_out, img_in)
示例#13
0
            #Stain space conversion
            source_ihc_hrd = separate_stains(source_ihc_rgb, hrd_from_rgb)

            source_Hema_Gray_Array = stainspace_to_2d_array(source_ihc_hrd, 0)
            source_red_Gray_Array = stainspace_to_2d_array(source_ihc_hrd, 1)
            source_DAB_Gray_Array = stainspace_to_2d_array(source_ihc_hrd, 2)

            normalized_source_Hema = normalize_mapping(source_Hema_Gray_Array, np.mean(source_Hema_Gray_Array), np.mean(target_Hema_Gray_Array))
            normalized_source_red = normalize_mapping(source_red_Gray_Array, np.mean(source_red_Gray_Array), np.mean(target_red_Gray_Array))
            normalized_source_DAB = normalize_mapping(source_DAB_Gray_Array, np.mean(source_DAB_Gray_Array), np.mean(source_DAB_Gray_Array))


            normalized_ihc_hrd = np.dstack((normalized_source_Hema, normalized_source_red, normalized_source_DAB))

            normalized_ihc_rgb = combine_stains(normalized_ihc_hrd, rgb_from_hrd)


            #Plot images
            fig, axes = plt.subplots(2, 2, figsize=(12, 11))
            #ax0 = axes.ravel()
            ax0, ax1,  ax2, ax3 = axes.ravel()

            ax0.imshow(source_ihc_rgb, cmap=plt.cm.gray, interpolation='nearest')
            ax0.set_title("Original source")

            ax1.imshow(target_ihc_rgb, cmap=plt.cm.gray, interpolation='nearest')
            ax1.set_title("original target")

            ax2.imshow(normalized_ihc_rgb, cmap=plt.cm.gray)
            ax2.set_title("normalized source")