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.