How to replace intensity of pixels in a specific region with a value from another region within the same image?
4 views (last 30 days)
The following code below is used to open up all 100 images but display one of them. For the image, the code asks the user to input a pixel value, which I input as 5000 to represent the metal artefact and is then shown as red. However, I now want to edit this code so that instead of this the pixel values of the metal are replaced with the pixel values of the surrounding tissue. So I want to make a loop for each row of pixels that is less than 5000 to be replaced with the pixel value that is +/- 15 pixels, of the surrounding tissue.
Any help would be greatly appreciated
ROI = [ 1350 1450 750 900];
A=input('type in pixel value for artifact');
for k = 1:100
fileName = sprintf('paganin_000%03d.png', k);
% If the file exists, display it.
imageData = imread(fileName);
imageData = imageData(ROI(1):ROI(2),ROI(3):ROI(4));
imageMatrix(:,:,k) = imageData;
% Print alert for those files that don't exist.
fprintf('File not found: "%s".\n', fileName)
I = imageData;
mask = I <= A;
Ired = I;
Igreen = I;
Iblue = I;
Ired(mask) = max(I, , 'all');
Igreen(mask) = 0;
Iblue(mask) = 0;
img = cat(3, Ired, Igreen, Iblue);