如何将索引图像转换为MATLAB中的RGB图像? [英] How to convert an indexed image to rgb image in MATLAB?
问题描述
imagesc
来显示确定色差。如何将其转换为rgb,以便我可以进一步处理。编辑添加了一些图片,顶部是原始图片, 'imshow(C)','imagesc(C)'。然后我只想让'C'变量像imagec图像。是否有可能?
这里是我的编码,从高斯开始
%阅读图片
rgb = imread('barcode.jpg');
%调整图像
rgb = imresize(rgb,0.33);
%figure(),imshow(rgb);
%从RGB转换为灰色
Igray = rgb2gray(rgb);
BW2 = edge(Igray,'canny');
%figure(),imshow(BW2);
%执行Hough变换
[H,theta,rho] = hough(BW2);
%找到Hough变换中的峰值点b $ b peak = houghpeaks(H);
%找到条形的角度
barAngle = theta(peak(2));
J = imrotate(rgb,barAngle,'bilinear','crop');
%figure(),imshow(J);
Jgray = double(rgb2gray(J));
%计算梯度
[dIx,dIy] =梯度(Jgray);
%if min(dIx(:))<= -100&& max(dIx(:))> = 100 || min(dIy(:))≤-100& max(dIy(:))> = 100
如果barAngle <= 65&& barAngle> = - 65&& min(dIx(:))≤-100
B = abs(dIx) - abs(dIy);
else
B = abs(dIy) - abs(dIx);
end
低通滤波
H = fspecial('gaussian',20,10);
C = imfilter(B,H);
C = imclearborder(C);
figure(),imshow(C);
figure(),imagesc(C); colorbar;
编辑 在你的代码中, I did a gaussian filter and the image become index. I have to use Edited Added some images, top is the 'original image', 'imshow(C)', 'imagesc(C)' respectively. Then I just want the 'C' variable to be like imagesc image. Is it possible??
Edited Here is my coding, see from gaussian onward
RGB is just eye-candy at this point, you can't magically add information that isn't there. EDIT In your code, 这篇关于如何将索引图像转换为MATLAB中的RGB图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
C
是一个灰度图像,因为 B
是灰度图,它是由梯度 dIx
和 dIy
源自一个图像,你自己使用 Jgray = double(rgb2gray(J))显式地显示灰度; code>
imagesc
to show the determine the color difference. How can I convert it to rgb so that I can do further process.% 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)
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));