Loop through matrix to do calculations under conditions
Afficher commentaires plus anciens
Hello,
I'm a beginner with Matlab and I'd like to do some calculations for image processing.
Here is the deal :
I possess 2 matrices (B and C), which actually consist of 2 different images (M x N pixels). Each parameter of each matrix corresponds to the pixel information. I read the images with Imread, so it seems to me that the vectors are already indexed somewhat in Matlab.
I'd like to do the following calculation :
If abs( B-C ) > k/2; with k some coefficient (let's say 5, it doesn't matter, a number actually).
Do A = B - k. sign(B-C);
Else A = B;
By that I mean " if the difference B-C is more than half k, adding or substracting one k to B, depending on the sign of the difference. And thus, create A. "
I thought about some loop through the matrix to do the calculation, but all I can find so far on the internet is loops to replace the value of the matrix, and not to calculate under some conditions.
Waiting for some help, please tell me if you need more informations.
Thank you
Clément
2 commentaires
James Tursa
le 18 Mai 2016
Modifié(e) : James Tursa
le 18 Mai 2016
Did you mean abs(B-C) > k/2? If you don't use the abs, then it seems to me that the sign(B-C) will always be the same, and then the "adding or subtracting" part doesn't make sense to me. Please clarify.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!