简体   繁体   English

如何在MATLAB中将索引图像转换为RGB图像?

[英]How to convert an indexed image to rgb image in MATLAB?

I did a gaussian filter and the image become index. 我做了一个高斯滤波器,图像变成了索引。 I have to use imagesc to show the determine the color difference. 我必须使用imagesc来显示确定色差。 How can I convert it to rgb so that I can do further process. 我如何将其转换为rgb以便进行进一步处理。

Edited Added some images, top is the 'original image', 'imshow(C)', 'imagesc(C)' respectively. 编辑添加了一些图像,顶部分别是“原始图像”,“ imshow(C)”和“ imagesc(C)”。 Then I just want the 'C' variable to be like imagesc image. 然后我只希望'C'变量像imagesc image。 Is it possible?? 可能吗??

在此处输入图片说明在此处输入图片说明在此处输入图片说明

Edited Here is my coding, see from gaussian onward 编辑这是我的编码,从高斯开始

% Read Image
rgb = imread('barcode.jpg');
% Resize Image
rgb = imresize(rgb,0.33);
%figure(),imshow(rgb);
% Convert from RGB to Gray
Igray = rgb2gray(rgb);
BW2 = edge(Igray,'canny');
%figure(),imshow(BW2);
% Perform the Hough transform
[H, theta, rho] = hough(BW2);
 % Find the peak pt in the Hough transform
peak = houghpeaks(H);
 % Find the angle of the bars
barAngle = theta(peak(2));
J = imrotate(rgb,barAngle,'bilinear','crop');
%figure(),imshow(J);
Jgray = double(rgb2gray(J));
% Calculate the Gradients
[dIx, dIy] = gradient(Jgray);
%if min(dIx(:))<= -100 && max(dIx(:))>=100 || min(dIy(:))<=-100 && max(dIy(:))>=100
if barAngle <= 65 && barAngle >=-65 && min(dIx(:))<= -100
    B =  abs(dIx) - abs(dIy);
else
    B = abs(dIy) - abs(dIx);
end
% Low-Pass Filtering
H = fspecial('gaussian', 20, 10);
C = imfilter(B, H);
C = imclearborder(C);
figure(),imshow(C);
figure(),imagesc(C);colorbar;
RGB = ind2rgb(X,map)

RGB is just eye-candy at this point, you can't magically add information that isn't there. 在这一点上,RGB只是让人眼花can乱,您无法神奇地添加不存在的信息。

EDIT 编辑

In your code, C is a gray-scale image, because B is gray-scale which in terms is caused by the fact that it is composed from gradients dIx and dIy that originate from an image, you yourself make grayscale explicitly with the line Jgray = double(rgb2gray(J)); 在您的代码中, C是灰度图像,因为B是灰度图像,这是由于它是由源自图像的渐变dIxdIy构成的,因此您自己用Jgray = double(rgb2gray(J));线明确地进行了灰度Jgray = double(rgb2gray(J));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM