Transparent Edges on RGB picture

2 views (last 30 days)
Hello!
I have a RGB picture of a rear lamp ('RGBLuminanceRecording.png') and in a .mat file ('ActualEdge.mat') as a matrix the edges of the lighting region of the Luminance Recording. As you can see in the code below I can already combine those two data to one, so that we can see the RGB picture of the rear lamp with white boarders at the lighting region (edge of the rear lamp). My problem is, that the edge also belongs to the lighting region (it is its border) and I do not want to totally overwrite it with my edge mask. So I would like to make my mask to a transparent object and lay this object over the RGB picture. The result should be the RGB picture with the borders of the lighting region in white on it, but the white border should be transparent so that I can also see the RGB picture under the whith border, or at least its structure.
By the way --> of cause the size of the RGB picture is the same size that the ActualEdge matrix has. only that the ActualEdge matrix is a n x m and the RGB is a n x m x 3 because of the RGB characteristic.
I know that I should probably use the command alpha, but I dont know how to use it on a .mat file and an image. (Article to alpha: https://de.mathworks.com/help/matlab/ref/alpha.html) Also this article shows an familar example, but I could not fix my problem with the help of it: https://de.mathworks.com/company/newsletters/articles/image-overlay-using-transparency.html
I hope you can help me, I would be really thankful.
Thank you really much!
Best Raphael Pesch
My Actual Code:
RGB = imread('RGBLuminanceRecording.png');
ActualEdge = load('EdgeMask.mat');
ActualEdge = ActualEdge.EdgeMask; %
ActualEdgeRGB = 255 * repmat(uint8(ActualEdge), 1, 1, 3);
sizeActualEdgeRGB = size(ActualEdge); % is also the size of the RGB only without the 3rd dimension
for i=1:sizeActualEdgeRGB(1)
for j=1:sizeActualEdgeRGB(2)
if ActualEdgeRGB(i,j,1) == 255 && ActualEdgeRGB(i,j,2) == 255 && ActualEdgeRGB(i,j,3) == 255
RGB(i,j,1) = 255;
RGB(i,j,2) = 255;
RGB(i,j,3) = 255;
end
end
end
imwrite(RGB, 'RGBLuminanceRecordningWithBorders.png')

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 9 Jan 2020
Hi Raphael, it is difficult to give exact solution without your data, but you can use the example code below which superimposes edge data over an RGB image.
clear; clc; close all;
% Read the RGB image
peppers = imread('peppers.png'); % Read your image here
% Load the edge data from the .mat file
load edgeData.mat; % Read your mat file here
% Show the RGB image
figure; imshow(peppers);
% Make a solidwhite patch
white = cat(3, ones(size(edgePeppers)),ones(size(edgePeppers)), ones(size(edgePeppers)));
% Lay the solid white patch over the RGB image
hold on; h = imshow(white); hold off;
% Use the edge data pixels to control the transparency of each pixel in the white image
set(h, 'AlphaData', edgePeppers);
edgeOverRGB.png
Hope this helps!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!