Python Programming for Biology: Bioinformatics and Beyond


Figure 18.3 (Plate 7).  Matrix transformations of pixmap colours



Download 7,75 Mb.
Pdf ko'rish
bet274/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   270   271   272   273   274   275   276   277   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Figure 18.3 (Plate 7).  Matrix transformations of pixmap colours. A red-green

coloured (i.e. two-channel) fluorescence microscope image of a cell is shown alongside

colour-adjusted yellow-blue and red-cyan versions. Inset in each image is the RGB colour

transformation matrix relative to the red-green image.

Here it is notable that there is an alternative approach using SciPy (a scientific Python

package which is often installed alongside NumPy): the imread() function is provided in

the  ndimage  module,  to  create  an  array  directly  from  the  file  data.  Though  it  may  be

convenient  to  avoid  PIL,  without  an  Image  object  we  cannot  invoke  show()  to  easily

visualise the loaded data. Also, doing things this way will include the ‘alpha’ transparency

layer, so to get the same kind of array as above we take a slice of the first three (red, green

and blue) colour layers with [:,:,:3].

from scipy import ndimage

pixmap = ndimage.imread('examples/CellNucleusRedGreen.png')

pixmap = pixmap[:,:,:3]

The  next  task  is  to  define  a  colour  transformation  matrix.  The  way  to  think  of  this  is



that the three rows dictate how to modify red, green and blue respectively and the [r, g, b]

values within each row specify what the colour will become. Accordingly, in transform the

first row specifies that the red channel will be transformed into equal red and green (i.e.

yellow), the second row means that the green channel will become blue and the third row

is all zero and so any original blue is removed entirely (not that there is much in the test

image). The transformation is applied using a dot product, remembering that the order of

the arguments is important.

transform = array([[1.0, 1.0, 0.0],

[0.0, 0.0, 1.0],

[0.0, 0.0, 0.0]])

pixmap2 = dot(pixmap, transform)

img2 = pixmapToImage(pixmap2)

img2.show()

Pixmap data can be manipulated as floating point numbers, rather than just integers in

the range 0 to 255. In the next example the pixmap is converted to an array of float data

type, so the numbers fall in the range 0.0 to 255.0. Dividing by 255.0 the range becomes

0.0 to 1.0, which is handy for the next step, where the values of the pixmap are squared

(an  element-by-element  operation).  Squaring  colour  values  in  the  range  zero  to  one  is  a

convenient way of changing the brightness of the image; values will move towards zero,

but  the  upper  limit  is  still  1.0.  With  the  brightness  adjusted  the  array  can  be  converted

back into the range 0 to 255 to go back to PIL.

pixmap = array(pixmap, float)

pixmap /= 255.0

pixmap = pixmap ** 2

pixmap = array(255*pixmap, uint8)

img2 = pixmapToImage(pixmap)

img2.show()


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   270   271   272   273   274   275   276   277   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish