![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1228242/image.png)
HI so im changing the color of the image to green and blue but its not working one of them gives an error and the other gives a red color
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
DGM
2022-12-12
编辑:DGM
2022-12-12
What is the size of app.Image? If it's not MxNx3, then you'll have to find out why it's not.
For example, it's possible that app.Image started out as MxNx1. If you then tried to operate on it with the blueButton CBF, then it would be implicitly expanded to MxNx2.
My guess is that you're working with single channel (MxNx1) images and that this is your problem. If so, you'll have to provide all the missing channels when you expand it to a color image.
% a single-channel image
Agray = imread('cameraman.tif'); % mxnx1
% generate simple colorized copies by concatenation
zerochan = zeros(size(Agray),class(Agray)); % blank channel
Ared = cat(3,Agray,zerochan,zerochan);
Agreen = cat(3,zerochan,Agray,zerochan);
Ablue = cat(3,zerochan,zerochan,Agray);
montage({Ared Agreen Ablue},'size',[1 3])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1228242/image.png)
Alternatively, you could do the same thing by channel insertion.
% generate simple colorized copies by channel insertion
Ared = zeros([size(Agray,1) size(Agray,2) 3],class(Agray)); % blank image
Ared(:,:,1) = Agray;
% ... and so on
See also:
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!