How to black out bright spots on an image
3 次查看(过去 30 天)
显示 更早的评论
Hi there,
I am simply wondering if it is possible to black out a bright spot on a bmp image and still keep the original image. Basically if I try
M = raw_image(raw_image < threshold)
It will return a 1D array of all points that are less than the threshold. I have used regionfill, but this still fills out the space in question. I can creat a mask for the image. But how do I multiply that mask to the original image to get values of 0 at the bright spots, and keep the original values everywhere else. See the attached image to see the bright spot I am speaking of. It seems to me that a good mask can be created by just asking for all values less than 15. But then how can I use the 0's from the mask to completely black out the original image at those positions and still keep the original intensities elsewhere?
For better reference, here is the code I have been using for regionfill that has worked great. I simply now want to black out the bright spot instead of making the image seemless.
% prepare directory info
path_info = fullfile(path, '70mm.bmp');
dir_info = dir(path_info);
% read images
filename = strcat(path, dir_info.name);
% transpose used to watch the images as they move downward. This is only
% done because the images seem to move downward. In future, laser can be
% oriented such that the transpose is not necessary.
raw_image = imread(filename)';
figure()
imshow(raw_image*10)
avg = sum(sum(raw_image))/nnz(raw_image);
M1 = raw_image > avg;
[y,x] = ndgrid(1:size(M1, 1), 1:size(M1, 2));
centroid = mean([x(M1),y(M1)]);
x = nnz(M1(floor(centroid(1)),:));
y = nnz(M1(:,floor(centroid(2))));
avg = mean(mean(raw_image(centroid(1)-x/2:centroid(1)+x/2,centroid(2)-y/2:centroid(2)+y/2)));
std = std2(raw_image(centroid(1)-x/2:centroid(1)+x/2,centroid(2)-y/2:centroid(2)+y/2));
threshold = avg + 2*std; %max(max(raw_image))/2;
M = raw_image > threshold;
Mp1 = regionfill(raw_image,M);
figure()
imshow(Mp1*10)
Thank you!
0 个评论
采纳的回答
Ameer Hamza
2020-5-22
编辑:Ameer Hamza
2020-5-22
You can use the following indexing like this to set pixels above the threshold to zero directly
raw_image(raw_image > threshold) = 0;
Also, you can multiply a mask with an image like this
mask = raw_image < threshold;
new_image = raw_image.*mask;
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!