Borrar filtros
Borrar filtros

How to covert back the gray scale image into rgb?

3 visualizaciones (últimos 30 días)
john karli
john karli el 6 de Dic. de 2021
Comentada: yanqi liu el 7 de Dic. de 2021
I am trying to crop the image using its pixel value and the n convert into rgb again but when i get back the rgb image its in the yellow back ground.
img1 = imread('snr30i4ASK100.png'); % imread( ) can load images of many formats
img1 = rgb2gray(img1);
row_i = find(any(img1<255,2));
first_rowi = row_i(1);
last_rowi = row_i(end);
col_i = find(any(img1<255,1));
first_coli = col_i(1);
last_coli = col_i(end);
new_imgi = img1(first_rowi:last_rowi, first_coli:last_coli);
rgbImage = ind2rgb(new_imgi, colormap);
I also upload the input image and its output

Respuesta aceptada

yanqi liu
yanqi liu el 7 de Dic. de 2021
Editada: yanqi liu el 7 de Dic. de 2021
yes,sir,may be check the colormap,such as
close all;
clear all;
clc;
img1 = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/824690/snr30i4ASK100.png'); % imread( ) can load images of many formats
imgt = img1;
img1 = rgb2gray(img1);
row_i = find(any(img1<255,2));
first_rowi = row_i(1);
last_rowi = row_i(end);
col_i = find(any(img1<255,1));
first_coli = col_i(1);
last_coli = col_i(end);
new_imgi = img1(first_rowi:last_rowi, first_coli:last_coli);
% rgbImage = ind2rgb(new_imgi, colormap);
bw=new_imgi>180;
rgbImage = ind2rgb(bw, [0 0 1;1 1 1]);
figure; imshow(mat2gray(rgbImage))
rgbImage2 = imgt(first_rowi:last_rowi, first_coli:last_coli,:);
figure; imshow(mat2gray(rgbImage2))
  3 comentarios
john karli
john karli el 7 de Dic. de 2021
any why you use mat2gray(rgbImage2). if we use just imshow(rgbImage2) it will same as mat2gray(rgbImage2)
yanqi liu
yanqi liu el 7 de Dic. de 2021
yes,sir
bw=new_imgi>180; % make the image to black and white
rgbImage = ind2rgb(bw, [0 0 1;1 1 1]); % make 0 and 1 to color blue and white
rgbImage2 = imgt(first_rowi:last_rowi, first_coli:last_coli,:); % this is to crop the origin image
mat2gray(rgbImage2). if we use just imshow(rgbImage2) it will same as mat2gray(rgbImage2)
use it to display in [0,1] range

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by