remove periodical like lines from the image
37 ビュー (過去 30 日間)
古いコメントを表示
Hi people,
I have a question to you. I have this kind of picture:
You see kind of horizontal lines through the image. I'd like to remove them. What do you think can I do?
The mat file of matrix is attached here.
Thank you very much.
2 件のコメント
採用された回答
Rik
2022 年 12 月 27 日
I actually suspect the bands are actual data and the circles are not, but without the context that is hard to tell.
S=load('matrix2see');
im=S.picture;
subplot(1,2,1)
imshow(im,[])
minmax=[min(im(:)) max(im(:))];
%create a column vector to use as a convolution kernel
kernel=ones(15,1);kernel=kernel/sum(kernel(:));
im2=conv2(im,kernel,'same');
subplot(1,2,2)
imshow(im2,minmax)
As you can see, that blurs the image a fair bit. What might perhaps work better is to subtract the mean of each row. This will only work if the bands are perfectly alligned to the grid.
figure
im3=im-mean(im,2);
imshow(im3,[])
You can fine-tune this second method by using a moving average instead of averaging the entire image.
6 件のコメント
その他の回答 (2 件)
Image Analyst
2022 年 12 月 27 日
We really need to know what gave rise to the lines. For example are you using a line scan camera and the lighting is flickering?
What I'd do is to take the mean of the image horizontally and divide the image by the mean. That would compensate for the case where the row of the image is good, it's just the wrong brightness.
S = load('matrix2see')
grayImage = S.picture;
% imwrite(mat2gray(grayImage), 'dimani4.png')
[rows, columns, numberOfColorChannels] = size(grayImage)
subplot(1,2,1)
imshow(grayImage,[])
title('Original Image')
rowMeans = mean(grayImage, 2);
repairedImage = grayImage ./ repmat(rowMeans, [1, columns]);
subplot(1,2,2)
imshow(repairedImage,[])
title('Repaired Image')
It looks like the rows means are not perfect, either because the lighting changes as the scan goes across, or the presence of particles in there affects the mean, changing it from it's true value. If you could get the means from a totally blank shot, it would help, but that assumes the pattern of lines stays fixed from one shot to the next.
4 件のコメント
Image Analyst
2022 年 12 月 29 日
If you're happy with the result, that's fine. The moving mean will blur the image more than a moving median. But maybe the blur is not important for what you need to do with the image. If it's really important you can rescan the sample and tell everyone not to talk.
George Heath
2024 年 10 月 9 日
Hi Dimani,
An alternative way is fit 1st or 2nd order polynomials to each line:
img =picture;
polyx = 1; %change to 2 for 2nd order polynomial
xl = 1:size(img,2);
for i =1:size(img,1)
y1 = img(i,:);
x1 = xl;
[p,~,mu] = polyfit(x1,y1,polyx);
result(i,:) = img(i,:) - polyval(p,1:size(img,2),[],mu);
end
imagesc(result)
This can then be refined with thresholding to exclude high or low regions, this example using the otsu method to auto threshold:
min_max(2) = multithresh(result,1);
min_max(1) = -inf;
imgt = (result<=min_max(2)).*(result>=min_max(1));
imgt(imgt==0) = NaN;
xl = 1:size(result,2);
for i =1:size(result,1)
pos = imgt(i,:)>0;
if sum(pos)>polyx+5
y1 = result(i,pos);
x1 = xl(pos);
[p,~,mu] = polyfit(x1,y1,2);
result2(i,:) = result(i,:) - polyval(p,1:size(result,2),[],mu);
else
result2(i,pos) = result(i,pos);
end
end
imagesc(result2)
The full codes for plane and line leveling are avalible in a GUI and as source code (see filter_img_v2)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!