Histogram normalization of two images using IHS

조회 수: 6 (최근 30일)
Tanya
Tanya 2014년 5월 11일
댓글: Image Analyst 2014년 5월 12일
I want a matlab code that will normalize one image taking other as reference using IHS I already have the seperate I, H and S components. I have to compute standard deviation and mean of H and S and then determine a new value and assign to H and S of target image. My code yields an error
clear;
clc;
img_a = imread('E:\TM\tanya\img3.tif');%reference
img_b = imread('E:\TM\tanya\img4.tif');%Target
%computing components for Target image
[r c] = size(img_a);
img_b_re = imresize(img_b,[r c],'bilinear');
img_b=im2double(img_b);
r=img_b(:,:,1);
g=img_b(:,:,2);
b=img_b(:,:,3);
th=acos((0.5*((r-g)+(r-b)))./((sqrt((r-g).^2+(r-b).*(g-b)))+eps));
H=th;
H(b>g)=2*pi-H(b>g);
H=H/(2*pi);
S=1-3.*(min(min(r,g),b))./(r+g+b+eps);
I=(r+g+b)/3;
hsi=cat(3,H,S,I);
HE=H*2*pi;
HE=histeq(HE);
HE=HE/(2*pi);
SE=histeq(S);
IE=histeq(I);
%figure, imshow(hsi),title('HSI Image');
img_b_re_hsi = hsi;
I = img_b_re_hsi(:,:,3);
hespc = imhist(I);
%RV=cat(3,HE,SE,IE);
% C=hsitorgb(RV);
% figure, imshow(C),title('RGB Image-HSI Normalized target image');
%computing components for reference image
img_a=im2double(img_a);
[r c] = size(img_b);
img_a_re = imresize(img_a,[r c],'bilinear');
r1=img_a(:,:,1);
g1=img_a(:,:,2);
b1=img_a(:,:,3);
th1=acos((0.5*((r1-g1)+(r1-b1)))./((sqrt((r1-g1).^2+(r1-b1).*(g1-b1)))+eps));
H1=th1;
H1(b1>g1)=2*pi-H(b1>g1);
H1=H1/(2*pi);
S1=1-3.*(min(min(r1,g1),b1))./(r1+g1+b1+eps);
I1=(r1+g1+b1)/3;
hsi1=cat(3,H1,S1,I1);
HE1=H1*2*pi;
HE1=histeq(HE1);
HE1=HE1/(2*pi);
SE1=histeq(S1);
IE1=histeq(I1);
%figure, imshow(hsi1),title('HSI Image 1');
img_a_re_hsi = hsi1;
I = img_a_re_hsi(:,:,3);
hespc1 = imhist(I1);
SH=std(H);
%M=mean(H);
% SH1=std(H1);
SS=std(S);
%MS=mean(S);
meanIm=mean([H(:) ; H1(:)]);
meanSat=mean([S(:) ; S1(:)]);
%SS1=std(S1);
Hnew = (SH*100)/meanIm;
Snew = (SS*100)/meanSat;
hsinew = cat(3,Hnew,Snew,I1);
figure, imshow(S3),title('IHS normalised RGB Image');
figure,imshow(img_a),title('Original');
C=hsitorgb(hsinew);
figure, imshow(C),title('RGB Image');
ERROR: ??? Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> Histonorm at 70 hsinew = cat(3,Hnew,Snew,I1);

채택된 답변

Image Analyst
Image Analyst 2014년 5월 11일
Well, what are the dimension/sizes of Hnew, Snew, and I1? They all have to match since they are going to be 2D slices out of a 3D image.
  댓글 수: 3
Tanya
Tanya 2014년 5월 12일
The error still persist
Image Analyst
Image Analyst 2014년 5월 12일
Please attach your images.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by