Effacer les filtres
Effacer les filtres

How to covert back the gray scale image into rgb?

3 vues (au cours des 30 derniers jours)
john karli
john karli le 6 Déc 2021
Commenté : yanqi liu le 7 Déc 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

Réponse acceptée

yanqi liu
yanqi liu le 7 Déc 2021
Modifié(e) : yanqi liu le 7 Déc 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 commentaires
john karli
john karli le 7 Déc 2021
any why you use mat2gray(rgbImage2). if we use just imshow(rgbImage2) it will same as mat2gray(rgbImage2)
yanqi liu
yanqi liu le 7 Déc 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by