2014-10-24 8 views
1

두 이미지, 그레이 스케일 이미지 및 RGB 이미지를 조작하려면 다음 MATLAB 코드가 필요합니다. 요점은 두 이미지 모두에 Average, GaussianLaplacian 필터를 적용하는 것입니다.RGB 이미지에 Matlab 이미지 필터 적용

%%Clear 
clear 
clc 
%%Reading images 
gray=imread('cameraman.tif') 
[gray_table gray_map]=gray2ind(gray,256) 
rgb=imread('peppers.png') 
[rgb_table rgb_map]=rgb2ind(rgb,256) 
%%Creating filters 
average=fspecial('average',3) 
gaussian=fspecial('gaussian',3,0.5) 
laplacian=fspecial('laplacian',0.9) 
%%Applying filters 
average_filterd_gray_table=imfilter(gray_table,average) 
gaussian_filterd_gray_table=imfilter(gray_table,gaussian) 
laplacian_filterd_gray_table=imfilter(gray_table,laplacian) 
average_filterd_rgb_table=imfilter(rgb_table,average) 
gaussian_filterd_rgb_table=imfilter(rgb_table,gaussian) 
laplacian_filterd_rgb_table=imfilter(rgb_table,laplacian) 
%%view 
figure 
subplot(1,4,1),imshow(gray_table,gray_map),title('Original Indexed Gray') 
subplot(1,4,2),imshow(average_filterd_gray_table,gray_map),title('Average Filtered Indexed Gray') 
subplot(1,4,3),imshow(gaussian_filterd_gray_table,gray_map),title('Gaussian Filtered Indexed Gray') 
subplot(1,4,4),imshow(laplacian_filterd_gray_table,gray_map),title('Laplacian Filtered Indexed Gray') 
figure 
subplot(1,4,1),imshow(rgb_table,rgb_map),title('Original Indexed RGB') 
subplot(1,4,2),imshow(average_filterd_rgb_table,rgb_map),title('Average Filtered Indexed RGB') 
subplot(1,4,3),imshow(gaussian_filterd_rgb_table,rgb_map),title('Gaussian Filtered Indexed RGB') 
subplot(1,4,4),imshow(laplacian_filterd_rgb_table,rgb_map),title('Laplacian Filtered Indexed RGB') 

회색조 이미지의 경우 코드가 올바르게 작동합니다. 그러나 RGB 이미지에서는 왜곡 된 결과 만 나타납니다. 그것을 고치는 방법?

+2

필터를 각 채널에 개별적으로 적용 해 보셨습니까? 아니면 각 HSV 채널에 별도로? 아니면 그냥 HSV의 "V"채널 – Dan

+0

@ 단 당신은 그것을 코드하시기 바랍니다 수 있을까요? – HussainBiedouh

+0

제안 된 답변 중 어떤 것도 도움이 되었습니까? 그렇다면 하나를 받아 들여서 스레드를 닫으십시오. –

답변

2

rgb2ind의 문서에 따르면 (here 클릭) :

그래서 같은 RGB 이미지를로드 할 때 :

[X,map] = rgb2ind(RGB,n)의 의사가 말한다 : 결과 이미지의

참고 값 X는 컬러 맵 맵에 대한 인덱스이므로 필터링 작업으로 과 같이 수학 처리에 사용하면 안됩니다.

RGB 이미지를 직접 필터링하는 것이 좋습니다. 미세 다음 작품 :

clear 
clc 
close all 

RGBImage = imread('peppers.png'); 

average = fspecial('average',3); 
gaussian=fspecial('gaussian',3,0.5); 
laplacian=fspecial('laplacian',0.9); 

RGB_Average = imfilter(RGBImage,average); 
RGB_Gaussian= imfilter(RGBImage,gaussian); 
RGB_Laplacian = imfilter(RGBImage,laplacian); 

figure; 
subplot(2,2,1) 
imshow(RGBImage) 
title('Original') 

subplot(2,2,2) 
imshow(RGB_Average) 
title('Average') 

subplot(2,2,3) 
imshow(RGB_Gaussian) 
title('Gaussian') 

subplot(2,2,4) 
imshow(RGB_Laplacian) 
title('Laplacian') 

이 제공 :

enter image description here

+0

그래, 그럼 왜 인덱스 된 그레이 스케일 이미지로 잘 돌아 갔지? – HussainBiedouh

+1

@Djhseen'gray_table'은'gray'와 같기 때문에'rgb'에는 맞지 않습니다. – Rashid

+0

그래, rgb/truecolor 룩업 테이블은 3D와 회색 그라데이션 이미지의 2D입니다. 모든 값은 그레이 스케일 (r, g 및 b)의 3 차원에서 유사하지만 rgb에서는 그렇지 않습니다. –

0

난 당신이 작동하는지, gray2indrgb2ind를 사용할 필요가 없습니다 생각합니다.

gray=imread('cameraman.tif'); 
rgb=imread('peppers.png'); 
%%Creating filters 
average=fspecial('average',3); 
gaussian=fspecial('gaussian',3,0.5); 
laplacian=fspecial('laplacian',0.9); 
%%Applying filters 
average_filterd_gray=imfilter(gray,average); 
gaussian_filterd_gray=imfilter(gray,gaussian); 
laplacian_filterd_gray=imfilter(gray,laplacian); 
average_filterd_rgb=imfilter(rgb,average); 
gaussian_filterd_rgb=imfilter(rgb,gaussian); 
laplacian_filterd_rgb=imfilter(rgb,laplacian); 
%%view 
figure 
subplot(2,2,1),imshow(gray),title('Original Indexed Gray') 
subplot(2,2,2),imshow(average_filterd_gray),title('Average Filtered Indexed Gray') 
subplot(2,2,3),imshow(gaussian_filterd_gray),title('Gaussian Filtered Indexed Gray') 
subplot(2,2,4),imshow(laplacian_filterd_gray),title('Laplacian Filtered Indexed Gray') 
figure 
subplot(2,2,1),imshow(rgb),title('Original Indexed RGB') 
subplot(2,2,2),imshow(average_filterd_rgb),title('Average Filtered Indexed RGB') 
subplot(2,2,3),imshow(gaussian_filterd_rgb),title('Gaussian Filtered Indexed RGB') 
subplot(2,2,4),imshow(laplacian_filterd_rgb),title('Laplacian Filtered Indexed RGB') 
2

다음과 같은 방법으로 이미지를 읽는이로

rgb=imread('peppers.png') 
[rgb_table rgb_map]=rgb2ind(rgb,256); 

, 당신은 필터의 적용 할 수 있기 때문에 당신은 이미지 색상을 일부 변경했다 적용된 방법 :

[rgb_table rgb_map]=imread('peppers.png') 
average=fspecial('average',3); 
gaussian=fspecial('gaussian',3,0.5); 
laplacian=fspecial('laplacian',0.9); 
average_filterd_rgb_table=imfilter(rgb_table,average); 
gaussian_filterd_rgb_table=imfilter(rgb_table,gaussian); 
laplacian_filterd_rgb_table=imfilter(rgb_table,laplacian); 
subplot(2,2,1),imshow(rgb),title('Original Indexed RGB') 
subplot(2,2,2),imshow(average_filterd_rgb_table),title('Average Filtered Indexed RGB') 
subplot(2,2,3),imshow(gaussian_filterd_rgb_table),title('Gaussian Filtered Indexed RGB') 
subplot(2,2,4),imshow(laplacian_filterd_rgb_table),title('Laplacian Filtered Indexed RGB') 

이다 이미지가 내가 얻을 :

관련 문제