Is there a coder-supported alternative to imsubtract?

Illustration
Blaine Minden - 2022-01-11T11:52:14+00:00
Question: Is there a coder-supported alternative to imsubtract?

Hello,   I am moving some Matlab code from working in Matlab to working in C through the Matlab Coder. I use the function imsubtract to see the difference between two photos. I was curious if anyone knows the best way to develop an alternative to imsubtract that is coder-supported? Also, I am working with Matlab 2014b   Thanks

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

Hello Blaine,
 
imsubtract is a fairly simple function, though robust to deal with the different types of images it may be fed. If you already know information on your images, you can simplify its use to apply to just your images. This basic code should be coder-compatible.
 
For example, if you know that you'll have only uint8 integer images, you can just do:
 
Z = X-Y;

If you have a double image, then you may have to deal with out of bounds issues (since double images are supposed to be between 0 and 1):

Z = X-Y;
Z(Z < 0) = 0;

Of course, all this also assumes valid input, and that X and Y are the same size (or scalar), which imsubtract would normally take care of. So if you're concerned about the input, you may need to write your own error checking.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!