Code explanation (bw)
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Image Analyst
2021-11-15
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 个评论
Awais Saeed
2021-11-15
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 个评论
yanqi liu
2021-11-15
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 个评论
Image Analyst
2021-11-15
Nice illustration/demo. Like I said in my answer, you do not need bw2(:)~=0. You can simply replace it by bw2
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!