Code explanation (bw)
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Any one know what is the meaning of this coding?
imageOutR(bw2(:)~=0) = Ro(bw2(:)~=0);
imageOutG(bw2(:)~=0) = Go(bw2(:)~=0);
imageOutB(bw2(:)~=0) = Bo(bw2(:)~=0);
Dccc = cat(3,imageOutR,imageOutG,imageOutB);
how to explain this code?
imageOutR(bw2(:)~=0) = Ro(bw2(:)~=0);
0 comentarios
Respuestas (3)
Image Analyst
el 15 de Nov. de 2021
It's someone (not a super skilled MATLAB programmer evidently) trying to take part of R, G, and B images that are defined by a mask (logical, binary image), bw2, and put them into different R, G, and B images, which they then concatenate into an RGB image called Dcc. It could be written simpler as:
imageOutR(bw2) = Ro(bw2); % Paste Red image inside bw2 onto imageOutR
imageOutG(bw2) = Go(bw2); % Paste Green image inside bw2 onto imageOutG
imageOutB(bw2) = Bo(bw2); % Paste Blue image inside bw2 onto imageOutB
% Concatenate individual color channels into a 3-D true color RGB image.
Dccc = cat(3,imageOutR,imageOutG,imageOutB);
0 comentarios
Awais Saeed
el 15 de Nov. de 2021
The (:) reshapes a matrix into a column vector.
imageOutR = [zeros(1,3); 2 5 13; 0 1 2; 1 3 5] % 4x4 matrix for instance
bw2 = randi([0 1],1,10)
% get indices of bw2 where non-zero elements resides
% get elements of imageOutR at those indices
imageOutR(bw2(:)~=0)
Ro = magic(4)
% replace elements of imageOutR with corresponding Ro's elements at those indices
imageOutR(bw2(:)~=0) = Ro(bw2(:)~=0)
cat() is for concatenation of arrays
0 comentarios
yanqi liu
el 15 de Nov. de 2021
sir,may be check it by some demo
clc; clear all; close all;
RGB = imread('football.jpg');
% 3 channel
Ro=RGB(:,:,1);Go=RGB(:,:,2);Bo=RGB(:,:,3);
% make mask
bw2 = im2bw(RGB);
% get mask data in image
imageOutR = zeros(size(Ro));imageOutG = zeros(size(Ro));imageOutB = zeros(size(Ro));
imageOutR(bw2(:)~=0) = Ro(bw2(:)~=0);
imageOutG(bw2(:)~=0) = Go(bw2(:)~=0);
imageOutB(bw2(:)~=0) = Bo(bw2(:)~=0);
Dccc = uint8(cat(3,imageOutR,imageOutG,imageOutB));
figure;
montage({RGB,bw2,Dccc}, 'Size', [1 3], 'BackgroundColor', 'r', 'BorderSize', [3 3])
2 comentarios
Image Analyst
el 15 de Nov. de 2021
Nice illustration/demo. Like I said in my answer, you do not need bw2(:)~=0. You can simply replace it by bw2
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!