필터 지우기
필터 지우기

How to remove red from the image

조회 수: 63 (최근 30일)
Divya Kumar
Divya Kumar 2024년 3월 20일
댓글: Divya Kumar 2024년 3월 21일
Hello,
I want to remove the red spots in the image not from the background. Please see the attached image. Please help!
  댓글 수: 1
DGM
DGM 2024년 3월 21일
What exactly do you mean "remove the red spots in the image not from the background"?
Specifically, what do you mean "remove"? What should the red areas be replaced by?
By "in the image not from the background" do you mean to remove only disconnected red regions?
If you created this image, then you should be working with the mask that was used to create the red parts of the image to begin with. We shouldn't be wasting our time with a damaged JPG screenshot of random size. JPG should never be part of the image processing routine, and neither should screenshots.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
DGM 2024년 3월 21일
If you created the original image, then you shouldn't even be trying to do this. Processing damaged mis-sized screenshots is only adding pointless complexity to the workflow and it adds heaps of error into any sort of quantitative analysis. Save images using imwrite(). Don't save screenshots. If you don't understand the problems with using JPG, then don't use it.
Here's a thing. I still think it's a bad idea to even use this image, but if there's no other option, well at least this is more useful than an AI-generated list of bullet points.
% save the actual image
% not a screenshot of the image
% don't save as JPG
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1647221/image.jpeg');
% crop off all the padding left from taking a screenshot
inpict = imcrop(inpict,[348.51 35.51 980.98 819.98]);
% get a mask
[H S V] = rgb2hsv(inpict);
mk = S>0.5; % pick some threshold
mk = imclearborder(mk); % get rid of the part connected to the border
% do something with the mask?
fillcolor = [0 1 0]; % pick some fill color
outpict = permute(fillcolor,[1 3 2]).*mk + im2double(inpict).*(1-mk);
% show whatever is left
imshow(outpict,'border','tight')
Red regions which are not connected to the background are filled with green for sake of demonstration. The mask coverage will be guaranteed to be inaccurate due to the JPG compression. Some red regions will be overselected. Some will be underselected.
If that's not what you wanted, you'll have to be clear about what you want.
  댓글 수: 1
Divya Kumar
Divya Kumar 2024년 3월 21일
Thank you! Your code helped me to get what I wanted.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Pratyush
Pratyush 2024년 3월 21일
Hi Divya,
To remove red spots from an image in MATLAB without affecting a red background, follow these steps:
  • Load your image with "imread" and display it using "imshow".
  • Convert the image from RGB to HSV color space using "rgb2hsv" for easier color segmentation.
  • Define thresholds for hue, saturation, and value to isolate red areas. This step requires experimentation to differentiate spots from the background. Create a binary mask based on these thresholds.
  • Use morphological operations like "bwareaopen" to remove noise and small objects from the mask. Further refine the mask as needed to accurately capture the red spots.
  • Use the refined mask to alter or remove the red spots from the original image. This could involve setting the spots to a different color or blending them with their surroundings.
Adjust the parameters (e.g., thresholds, size for "bwareaopen") based on your specific image to accurately target and remove the red spots without affecting the red background.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by