A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
MIT License
4.51k
stars
1.03k
forks
source link
error: OpenCV(4.6.0) /work/ci_py311/opencv-suite_1676837327081/work/modules/core/src/arithm.cpp:647: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op' #284
Hello, i'am currently blocked with this message error, can u help me guys plz, this is my code :
chemin_image = "/home/TNguyen2/Documents/FLAIR/img/927491-2000_6302587-2000_50.tif" chemin_msk = "/home/TNguyen2/Documents/FLAIR/msk/927491-2000_6302587-2000_50.tif" image = tiff.imread(chemin_image, 0) msk = tiff.imread(chemin_msk, 0)
Vérifier les tailles des images
if image.shape[:2] != msk.shape[:2]: raise ValueError("Les tailles des images ne correspondent pas.")
height, width = image.shape[:2]
crop_image = image[:height, :width] crop_msk = msk[:height, :width] msk_reduced = msk[:, :, :4] img_reduced = image[:, :, :4] image_gris = np.mean(image, axis=2).astype(np.uint8)
Convertir le masque en image binaire
masque_binaire = cv2.cvtColor(msk_reduced, cv2.COLORBGR2GRAY) , masque_binaire = cv2.threshold(masque_binaire, 127, 255, cv2.THRESH_BINARY)
Appliquer le masque à l'image en utilisant le masque binaire
superposition = cv2.bitwise_and(image_gris, image_gris, mask=masque_binaire)
resized_image = cv2.resize(crop_image, (crop_msk.shape[1], crop_msk.shape[0])) resized_msk = cv2.resize(crop_msk, (crop_image.shape[1], crop_image.shape[0])) superposition = cv2.addWeighted(resized_image, 0.3, crop_msk, 0.7, 0)
Afficher la superposition
cv2.imshow("Image", resized_image) cv2.imshow("Mask", crop_msk) cv2.waitKey(0) cv2.destroyAllWindows()