MATLAB: Remove Non Overlapping Pixels In Stitched Image

image processingMATLAB

Hey there, I'm unsure of how best to approach how to remove pixels that aren't overlapping (pixels from only one of the images) in my stitched images. An example is below, where you can see very obvious green / blue only sections which I am trying to remove.
Originally I have the three separated RGB images, and I combine them with the code below. (The optimizer and metrics are set, and the irBandImage is another image in the set, but is not part of this RGB image.)
if true
greenBandRegistered = imregister(greenBandImage, irBandImage, 'Rigid', optimizer, metric);
blueBandRegistered = imregister(blueBandImage, irBandImage, 'Rigid', optimizer, metric);
redBandRegistered = imregister(redBandImage, irBandImage, 'Rigid', optimizer, metric);
uint16CombinedImage = cat(3, redBandRegistered, greenBandRegistered, blueBandRegistered);
end
Any ideas on how to remove the non overlapping areas? I'm thinking if the average RGB values are less than 5 or something than to set the whole thing to 0, but I'm not sure how well this would work.

Best Answer

For anyone who may come across this in the future, I ended up removing the extra pixels with the following code. (Note: Will not work on images with 0s in RGB values in non-overlapping areas, however unlikely that may be, since it will set those to black)
if true
for i = 1 : size(greenBandRegistered,1)
for j = 1 : size(greenBandRegistered,2)
if redBandRegistered(i, j) == 0
greenBandRegistered(i,j) = 0;
blueBandRegistered(i,j) = 0;
irBandImage(i,j) = 0;
end
if greenBandRegistered(i, j) == 0
redBandRegistered(i,j) = 0;
blueBandRegistered(i,j) = 0;
irBandImage(i,j) = 0;
end
if blueBandRegistered(i, j) == 0
redBandRegistered(i,j) = 0;
greenBandRegistered(i,j) = 0;
irBandImage(i,j) = 0;
end
end
end
end