MATLAB Answers

How do I darken a certain part of the image?

20 views (last 30 days)
Özge Akbülbül
Özge Akbülbül on 22 May 2018
Commented: Rena Berman on 29 Jun 2021 at 14:35
Hello
I wanna do darken circle's around .Circle and its inside must stay like the way it is.How can i do that with simple way?Firstly i think about the nested for loops. i and j (row and cloumns) pixel values must be 1 or 0 respectively.Is this idea true?Can someone give me an advice for this?
  3 Comments
Rena Berman
Rena Berman on 29 Jun 2021 at 14:35
(Answers Dev) Restored edit

Sign in to comment.

Accepted Answer

Akira Agata
Akira Agata on 24 May 2018
One possible solution would be like this:
% Read the file and convert to gray-scale image
I = imread('b.jpg');
Igray = rgb2gray(I);
% Extract the circle by selecting the region with maximum bounding box
BW = imbinarize(Igray);
s = regionprops('table',~BW,'BoundingBox','PixelIdxList');
[~,idx] = max(s.BoundingBox(:,3).*s.BoundingBox(:,4));
% Make the mask image by filling the circle with 'true'
BWmask = false(size(BW));
BWmask(s.PixelIdxList{idx}) = true;
BWmask = imfill(BWmask,'holes');
% Mask the image
Iresult = Igray;
Iresult(~BWmask) = 0;
% Show the reusult
imshowpair(Igray,Iresult,'montage')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by