An warware: pytorch sami haษ—in kai tsakanin abin rufe fuska biyu

sami haษ—in kai tsakanin abin rufe fuska biyu A cikin duniyar sarrafa hoto da hangen nesa na kwamfuta, yin aiki tare da abin rufe fuska aiki ne na gama-gari kuma mai mahimmanci. Masks suna taimaka mana mu mai da hankali kan takamaiman yankuna na hoto da amfani da ayyuka daban-daban zuwa waษ—annan yankuna. ฦŠaya daga cikin ayyukan gama gari da ake yi akan abin rufe fuska shine gano mahadar tsakanin abin rufe fuska biyu. A cikin wannan labarin, za mu bincika wani bayani na Python don samun haษ—in kai tsakanin masks biyu da kuma samar da bayanin mataki-mataki na lambar. Za mu kuma tattauna dakunan karatu masu dacewa da ayyuka waษ—anda ke taimakawa wajen magance irin waษ—annan matsalolin.

Don magance matsalar haษ—in kai, za mu yi amfani da mashahurin ษ—akin karatu na Python, NumPy. NumPy babban ษ—akin karatu ne mai ฦ™arfi wanda ke ba da goyan baya don aiki tare da manyan, tsararraki masu girma dabam da matrices, da kuma babban tarin manyan ayyuka na lissafi don aiki akan waษ—annan tsararrun.

Samun Matsayin Masks Biyu

Don farawa, za mu buฦ™aci masks guda biyu, waษ—anda aka wakilta a matsayin tsararru na siffar da girman girman, inda kowane kashi ya dace da pixel a cikin hoton. Don sauฦ™i, za mu yi amfani da masks na binary tare da ฦ™imar 0 (baฦ™ar fata) da 1 (fararen fata). Za'a iya ฦ™ididdige mahaษ—in mashin ษ—in ta hanyar yin amfani da mashin-hikima mai hikima.

Anan ga matakin mataki-mataki na lambar:

import numpy as np

def mask_intersection(mask1, mask2):
    return mask1 * mask2

1. Shigo da ษ—akin karatu na NumPy azaman np.
2. ฦ˜ayyade aikin da ake kira `mask_intersection' wanda ke ษ—aukar abin rufe fuska biyu azaman shigarwa.
3. Koma sakamakon haษ“aka-hikima na mashin shigar guda biyu.

Yanzu zaku iya amfani da wannan aikin mai sauฦ™i don ฦ™ididdige haษ—in gwiwar masks biyu. Misali:

mask1 = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0]])
mask2 = np.array([[1, 1, 1], [0, 1, 0], [1, 0, 0]])

intersection = mask_intersection(mask1, mask2)
print(intersection)

Wannan zai fitar da:

โ€œโ€œ
[1 0]
[0 1]
[1]
โ€œโ€œ

Matsayin NumPy a Gudanar da Hoto

Lambobi yana taka muhimmiyar rawa wajen sarrafa hoto da ayyukan hangen nesa na kwamfuta. Ingantacciyar ingantacciyar sa da ingantaccen matrix da ayyukan tsararru suna ba masu haษ“aka damar yin ฦ™ididdige ฦ™ididdiga da magudi akan hotuna cikin sauฦ™i. Misali, sarrafa abin rufe fuska, tace hoto, sauyi na Fourier, da ayyuka masu hikimar ka'ida sune kawai misalan abin da za'a iya cimma tare da taimakon NumPy.

Baya ga NumPy, akwai wasu ษ—akunan karatu waษ—anda ke taimakawa ayyukan sarrafa hoto kamar OpenCV, scikit-image, da PIL (Laburaren Hoto na Python). Waษ—annan ษ—akunan karatu suna ba da ayyuka daban-daban don lodawa, gyarawa, da adana hotuna ta nau'i daban-daban.

ฦ˜arin Ayyukan Mask

Bayan haษ—in kai, akwai wasu ayyukan abin rufe fuska da yawa waษ—anda galibi ana yin su a cikin sarrafa hoto da ayyukan hangen nesa na kwamfuta. Wasu daga cikinsu sune:

  • Kungiyar: Haษ—a abin rufe fuska biyu ta hanyar yin aiki mai hikima KO aiki.
  • Bambanci: Yana cire abin rufe fuska ษ—aya daga wani bisa tushen hikima.
  • ฦ˜ara: Yana juya abin rufe fuska ta hanyar canza 1s zuwa 0s kuma akasin haka.

Ana iya aiwatar da waษ—annan ayyukan abin rufe fuska cikin sauฦ™i ta amfani da ayyukan NumPy da dabarun Python, kamar yadda muka sami mahadar abin rufe fuska biyu.

Shafi posts:

Leave a Comment