Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Thierryefrei opened this issue Jun 19, 2023 · 1 comment

Comments

@Thierryefrei
Copy link

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.COLOR_BGR2GRAY)
_, 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()

@msavinash
Copy link

Which "tiff" library are you using? Which image are you using? Please provide complete code and images to reproduce your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants