how to estimate bright channel for color image in Matlab??
3 次查看(过去 30 天)
显示 更早的评论
how to estimate the bright channel prior for color image (convert the image of the spatial domain into Brightness Domain) using the following formula:
Does anyone know how to do this in Matlab??
4 个评论
Rik
2019-3-12
So you want a window average, but with a maximum, with a 15-by-15-by-size(I,3) window?
采纳的回答
Image Analyst
2019-3-12
编辑:Image Analyst
2019-3-12
The inner operation is dilation. The outer one is max. So simply dilate each color channel (take the max in a 15x15 window) with imdilate(). Like for the red channel.
dilatedRed = imdilate(redChannel, ones(3));
Same for blue and green, then recombine into an rgb image and use max
brightnessImage = max(rgbImage, [], 3);
A full demo is attached.
But I don't recall seeing this formula you gave. Taking the max is what you do to get L in the RGB-to-HSL, or to get the V in RGB-to-HSV formula. But they don't do dilation first. Not sure what that gets you, do you know? Why not just do it without dilation and use the built-in rgb2hsv() function
hsvImage = rgb2hsv(rgbImage); % Convert to HSV color space.
brightnessImage = hsvImage(:, :, 3); % Extract the V channel.
5 个评论
Image Analyst
2019-3-13
Yes, except the order is switched. It is:
Imin = imerode(min(Ig, [], 3), ones(windowSize));
Where are you getting these formulas from? I can understand that the dark current signal might be estimated as the min of the red, green, and blue pixels in the demosaicing window but I really doubt any camera uses a demosaicing algorithm where the interpolated pixels are the uniformly weighted average inside a 15x15 window.
更多回答(1 个)
Rik
2019-3-12
Below you find 2.5 strategies. The first should be a lot faster, especially for larger images. With the last it is easier to see that the method returns the expected outcome.
clc
A=randi(20000,300,300,3);%random image
window=15;
%strategy 1:
tic
GetSingleLayerMax=@(A,window) nlfilter(A,[window window],@(x) max(x(:)));
maxIM=GetSingleLayerMax(A(:,:,1),window);
for n=2:size(A,3)
tmp=cat(3,maxIM,GetSingleLayerMax(A(:,:,n),window));
maxIM = max(tmp,[],3);
end
toc
%strategy 1b:
tic
GetSingleLayerMax2=@(A,window) colfilt(A,[window window],'sliding',@max);
maxIM_1b=GetSingleLayerMax2(A(:,:,1),window);
for n=2:size(A,3)
tmp=cat(3,maxIM_1b,GetSingleLayerMax2(A(:,:,n),window));
maxIM_1b = max(tmp,[],3);
end
toc
%strategy 2:
tic
maxIM2=zeros(size(A,1),size(A,2));
tmp=(1:window);tmp=tmp-mean(tmp);
tmp=ceil(tmp);%in case of even window size
[w_x,w_y,w_z]=meshgrid(tmp,tmp,1:size(A,3));
w=[w_x(:) w_y(:) w_z(:)];
for r=1:size(A,1)
for c=1:size(A,2)
%get all indices
tmp=w;
tmp(:,1)=w(:,1)+r;
tmp(:,2)=w(:,2)+c;
%remove invalid indices
tmp(any(tmp<1,2),:)=[];
tmp(tmp(:,1)>size(A,1),:)=[];
tmp(tmp(:,2)>size(A,2),:)=[];
%convert to linear indices
ind=sub2ind(size(A),tmp(:,1),tmp(:,2),tmp(:,3));
%compute the max
maxIM2(r,c)=max(A(ind));
end
end
toc
if isequal(maxIM,maxIM2) && isequal(maxIM_1b,maxIM2)
disp('everything finished succesfully')
else
disp('something went wrong (check for float rounding errors)')
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!