Borrar filtros
Borrar filtros

operation error (red,green,blue)

5 visualizaciones (últimos 30 días)
Shatha
Shatha el 2 de En. de 2023
Editada: DGM el 3 de En. de 2023

Respuestas (3)

Walter Roberson
Walter Roberson el 2 de En. de 2023
r(:, :, 2) = 0;
  1 comentario
Walter Roberson
Walter Roberson el 3 de En. de 2023
Note that you set b(:, :, 4) but imshow will not handle rows x columns x 4 images

Iniciar sesión para comentar.


DGM
DGM el 2 de En. de 2023
Editada: DGM el 3 de En. de 2023
Your indexing is going to cause problems. Setting channel 2 of an RGB image to 0 won't generally turn it red. I'm assuming that you don't have 4-channel images, and if you do, imshow() can't handle them. Also note that these assignments are going to behave unexpectedly if the image has only one channel.
If the image is already RGB, then
inpict = imread('peppers.png');
redpict = inpict;
redpict(:,:,2:3) = 0;
imshow(redpict)
greenpict = inpict;
greenpict(:,:,[1 3]) = 0;
imshow(greenpict)
bluepict = inpict;
bluepict(:,:,1:2) = 0;
imshow(bluepict)
If the images are grayscale, see these questions regarding similar recent assignments:
See also the comments here about basic colorization:
Note that there may be different goals. "Make the image red" might strictly mean "extract only the red channel", or it might mean "colorize the image in some manner so that it looks red". If the latter is the goal, the former is rarely an appealing approach. This can be seen in the above example. It's hard to "make the image blue" if there really isn't much blue content in it to begin with.
% crude colorization by uncorrected luma substitution
sz = size(inpict);
bluepict = cat(3,zeros([sz(1:2) 2]),rgb2gray(inpict));
imshow(bluepict)
% colorization using luma-corrected HSL (uses MIMT)
bluepict = gcolorize(inpict,[-120 100 0]);
imshow(bluepict)
% colorization by image blending in SRLAB2 (uses MIMT)
cpict = colorpict(imsize(inpict,2),[0 0 1]);
ypict = mono(inpict,'y');
bluepict = imblend(cpict,ypict,1,'colorlchsr');
imshow(bluepict)

Image Analyst
Image Analyst el 2 de En. de 2023
I couldn't see your image and had to zoom in 300% (not convenient). Plus we can't run or edit/fix an image, and if we did (by making an image for you like you did for us), it wouldn't be convenient for you to implement that fix. Post code as text, not an image.
Like @Walter said, you have an extra equals sign in there that you need to get rid of, if you want to do it your way.
We need to know what you really want. Do you want to show each individual color channel in grayscale, or with a colormap that is like their color? Maybe try
originalArray = app.Image;
% Extract planes 2, 3, and 4 as the Red, Green, and Blue channels respectively.
rgbImage = originalArray(:, :, 2:4);
[r, g, b] = imsplit(rgbImage);
ramp = 0:255;
z = zeros(256, 1);
axes(app.UIAxes_2);
switch value
case 'Red'
imshow(r);
cmap = [ramp, z, z];
case 'Green'
imshow(g);
cmap = [z, ramp, z];
case 'Blue' % Or Bluee (whatever you have)
imshow(b);
cmap = [z, z, ramp];
end
colormap(cmap);
colorbar
If you want it in grayscale, then don't call the colormap function
  1 comentario
DGM
DGM el 3 de En. de 2023
I'm assuming that if the assignment is like the others, they're making some sort of image editing app, so the single-color image(s) need to be retained as (ostensibly RGB) images. At least that's my interpretation of a handful of screenshots.

Iniciar sesión para comentar.

Categorías

Más información sobre Red en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by