How to covert back the gray scale image into rgb?
조회 수: 2 (최근 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
댓글 수: 0
채택된 답변
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
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!