Instead of multiplying pixels in the mask by a constant value, you can mulitply all pixels by an "image" of the saturation multiplier.
So rather than the scalar "1.6", which could as well have been a element-by-element multiplication, your original strategy could have been executed as
[M,N] = size(Imm)
satFactorMat = 1.6*ones(M,N);
satFactorMat(binaryImage) = 1.6;
saturationImage = saturationImage .* satFactorMat;
So now hopefully it is clear you don't really need the mask concept for the operation of altering the image itself, you just might use it to define the satFactorMat "topography", which looks like a mesa.Now you can just smooth it out using something like a smoothing function; you can use imgaussfilt
satFactorMat = imgaussfilt(satFactorMat,6);
You may need to convert everything to doubles first before doing the imgaussfilt and elementwise multiplication, and then convert back to uint8.
Also, note that multiplying is dangerous because you may end up with values outside valid range (>255). So it would be safe to exponentiate (but then you have to normalize your pixel values onto (0,1) first.
hsvImage = double(hsvImage)/255;
satPowerMat = ones(M,N);
satPowerMat(binaryImage) = 0.3;
satPowerMat = imgaussfilt(satPowerMat,6);
saturationImage = saturationImage .* satPowerMat;
hsvImage = cat(3, hueImage, saturationImage, valueImage);
hsvImage = uint8(hsvImage*255);
Best Answer