How to set specific color in an image as transparent?

11 次查看(过去 30 天)
In this image:
I would like to set the blue color rgb = [61 38 168] as transparent and save it to a new png. How can I do this? Thanks a lot
EDIT: additional information
Thanks to your answers. Because you ask yourself, what I want with this transparency I want to give you more information: First, I want to define the blue color as transparent:
to be able to georeference it like this:
Again, thanks for your help (I did this using Photoshop, but I would prefer doing this with Matlab... )

采纳的回答

Adam Danz
Adam Danz 2021-12-28
编辑:Adam Danz 2021-12-28
Load image
img = 'image.png';
I = imread(img);
figure()
tiledlayout(1,2)
ax1 = nexttile();
imshow(I,'Parent',ax1)
Isolate target color
targetColor = [61 38 168];
isTarget = I(:,:,1) == targetColor(1) & I(:,:,2) == targetColor(2) & I(:,:,3) == targetColor(3);
isTargetArray = repelem(isTarget, 1,1,3);
Updated: Plot isolated section on top of another image
ax2 = nexttile();
hold(ax2, 'on')
imshow(rand(size(I)),'Parent',ax2) % noise image
% Isolate section
img2 = imshow(I,'Parent',ax2);
% Set transparency
set(img2, 'AlphaDataMapping', 'none', 'AlphaData', double(~isTargetArray(:,:,1)));
  5 个评论
Adam Danz
Adam Danz 2021-12-28
I've updated my answer to show how to selectively add transparency to sections of the image.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2021-12-28
Use imoverlay
maskColor = [61 38 168];
% Create a new image where the mask is the specified color over the original rgb image.
image2 = imoverlay(originalRGBImage, maskImage, 'Color', maskColor);
imshow(image2);
where mask is your image and it's 0 where you want the original image to show through, the mask is 1 where you want the specified color. The color will be solid, 100% opaque.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by