How to covert back the gray scale image into rgb?

3 次查看(过去 30 天)
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

采纳的回答

yanqi liu
yanqi liu 2021-12-7
编辑:yanqi liu 2021-12-7
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 个评论
john karli
john karli 2021-12-7
any why you use mat2gray(rgbImage2). if we use just imshow(rgbImage2) it will same as mat2gray(rgbImage2)
yanqi liu
yanqi liu 2021-12-7
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by