How to replace intensity of pixels in a specific region with a value from another region within the same image?
Ältere Kommentare anzeigen
Hi,
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
clear all
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 isfile(fileName)
% If the file exists, display it.
imageData = imread(fileName);
%crop
imageData = imageData(ROI(1):ROI(2),ROI(3):ROI(4));
%imshow(imageData);
imageMatrix(:,:,k) = imageData;
else
% Print alert for those files that don't exist.
fprintf('File not found: "%s".\n', fileName)
end
end
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);
figure
imagesc(img)
Antworten (0)
Kategorien
Mehr zu Video Formats and Interfaces finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!