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

4 Ansichten (letzte 30 Tage)

Akzeptierte Antwort

DGM
DGM am 12 Dez. 2022
Bearbeitet: DGM am 12 Dez. 2022
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])
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:

Weitere Antworten (1)

Image Analyst
Image Analyst am 12 Dez. 2022
See attached demos for changing one color into another.

Community Treasure Hunt

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

Start Hunting!

Translated by