How to covert back the gray scale image into rgb?

2 ビュー (過去 30 日間)
john karli
john karli 2021 年 12 月 6 日
コメント済み: yanqi liu 2021 年 12 月 7 日
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by