Originally I had intended on doing a followup post on my Getting Started with Deep Learning Guide, but due to some unfortunate personal events, I wasn’t able to complete the blog post. But don’t worry…I still have a really great tutorial for you today!
Bad tutorials are worse than warm beer.
You want to know why?
Because you can always chug a warm beer down in a few seconds…
But you can spend hours going down the wrong path when reading a misguiding tutorial.
And that’s my inspiration for this post — I really hate all the blog posts I’ve seen that detail how to find the brightest spot of an image using OpenCV.
You see, they are leaving out a single line of code that is absolutely crucial to being more robust to noise.
Now, if you’re like me, that doesn’t sit well.
So sit back. Relax. And know that you’re about to read a good tutorial. You won’t spend hours wasting your time here.
In this blog post I’ll show you how to find the brightest spot in an image using Python and OpenCV…and I’ll show you the single line of pre-processing code you’ll need to improve your results.
Looking for the source code to this post?
Jump Right To The Downloads SectionOpenCV and Python versions:
This example will run on Python 2.7/Python 3.4+ and OpenCV 2.4.X/OpenCV 3.0+.
You Need More than cv2.minMaxLoc
A few weeks ago a PyImageSearch reader wrote in and asked about the best way to find the brightest spot in the image.
You see, they were working with retinal images (see the top of this post for an example). These images are normally orange or yellowish in color, circular, and contain important physical structures of the eye, including the optic nerve and the macula.
This reader wanted to know the best way to find the optic nerve center, which is normally the brightest spot of the retinal image.
To find the brightest spot of the image using Python and OpenCV, you would utilize the cv2.minMaxLoc
function.
However, the term “spot” here is a little misleading.
The “brightest spot” of the image according to cv2.minMaxLoc
actually isn’t a region — it’s simply the brightest single pixel in the entire image.
This means that the cv2.minMaxLoc
function is extremely susceptible to noise if you don’t take the necessary pre-cautionary steps. A single bright pixel in an area where there wouldn’t normally be a bright pixel (in this case, an area other than the optic nerve center) can dramatically throw off your results.
Instead, you are better off examining regions of the image, rather than a single pixel. When you examine regions you let the average balance everything out — and you’re less susceptible to noise.
So how do you mimic this “region” effect without explicitly examining each and every region of the image?
I’ll show you.
The rest of this blog post is dedicated to showing you how to find the brightest spot of an image using Python and OpenCV
Finding the Brightest Spot in an Image using Python and OpenCV
Let’s go ahead and get started.
Open up your favorite editor, create a new file named bright.py
, and let’s get started.
# import the necessary packages import numpy as np import argparse import cv2 # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", help = "path to the image file") ap.add_argument("-r", "--radius", type = int, help = "radius of Gaussian blur; must be odd") args = vars(ap.parse_args()) # load the image and convert it to grayscale image = cv2.imread(args["image"]) orig = image.copy() gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
On Lines 2-4 we’ll import the packages we’ll need. If you’re a regular PyImageSearch reader, these packages should feel like old hat to you now. We’ll use NumPy for numerical processing, argparse
to parse command line arguments, and cv2
for our OpenCV bindings.
From there, we’ll parse our command line arguments on Lines 7-11. Nothing too special here.
The first switch, --image
, is the path to the image we are going to find the brightest spot in. The second switch --radius
, is an integer indicating the radius of the Gaussian blur we are going to apply to the image.
It’s important to note that this radius value must be odd and not even.
Next up, lets go ahead and load the image on Line 14, make a clone of it on Line 15, and convert it to grayscale on Line 15.
The Susceptible Method:
Now, let’s go ahead and apply the suspectible method method to detecting the brightest spot in the image:
# perform a naive attempt to find the (x, y) coordinates of # the area of the image with the largest intensity value (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray) cv2.circle(image, maxLoc, 5, (255, 0, 0), 2) # display the results of the naive attempt cv2.imshow("Naive", image)
The susceptible method to finding the brightest spot in an image is to use the cv2.minMaxLoc
function without any pre-processing. This function requires a single argument, which is our grayscale image. Then, this function takes our grayscale image and finds the value and (x, y) location of the pixel with the smallest and largest intensity values, respectively.
To break it down: minVal
contains the smallest pixel intensity value, maxVal
contains the largest pixel intensity value, minLoc
specifies the (x, y) coordinates of minVal, and maxLoc
specifies the (x, y) coordinates of maxLoc
.
In this application, we’re only concerned with the pixel with the largest value, so we’ll grab that and draw a circle around the region on Line 20 and display it on Line 24.
The biggest problem with this method, and why I call it the susceptible method to find the brightest spot in an image, is that it’s extremely susceptible to noise.
A single pixel could dramatically throw off your results…
So how do we fix this?
Simple.
We’ll apply a Gaussian blurring through a pre-processing step.
The Slightly More Robust Method:
Let’s go ahead and check out how to do this:
# import the necessary packages import numpy as np import argparse import cv2 # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", help = "path to the image file") ap.add_argument("-r", "--radius", type = int, help = "radius of Gaussian blur; must be odd") args = vars(ap.parse_args()) # load the image and convert it to grayscale image = cv2.imread(args["image"]) orig = image.copy() gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # perform a naive attempt to find the (x, y) coordinates of # the area of the image with the largest intensity value (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray) cv2.circle(image, maxLoc, 5, (255, 0, 0), 2) # display the results of the naive attempt cv2.imshow("Naive", image) # apply a Gaussian blur to the image then find the brightest # region gray = cv2.GaussianBlur(gray, (args["radius"], args["radius"]), 0) (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray) image = orig.copy() cv2.circle(image, maxLoc, args["radius"], (255, 0, 0), 2) # display the results of our newly improved method cv2.imshow("Robust", image) cv2.waitKey(0)
Like I mentioned above, using cv2.minMaxLoc
without any pre-processing can leave you extremely susceptible to noise.
Instead, it’s better to first apply a Gaussian blur to the image to remove high frequency noise. This way, even pixels that have very large values (again, due to noise) will be averaged out by their neighbors.
On Line 28 we apply our Gaussian blur with the supplied radius from our command line argument.
Then we once again make a call to cv2.minMaxLoc
to find the brightest pixel in the image.
However, since we have applied a blurring pre-processing step, we’ve averaged all pixels together with the supplied radius
of each other. Doing this allows us to remove high frequency noise and leaves cv2.minMaxLoc
substantially less susceptible.
By using a larger radius we’ll be averaging over a larger neighborhood of pixels — thus mimicking larger regions of the image.
And by using a smaller radius we can average over smaller regions.
Determining the correct radius will heavily dependent on the application you are developing and the task you are trying to solve.
Results
Fire up a terminal and execute the following command:
$ python bright.py --image retina.png --radius 41
If all goes well, you should see the following image:
On the left we have the susceptible method using cv2.minMaxLoc
without any pre-processing and on the right we have the robust method.
But you’re probably looking at these images and saying, “Hey Adrian, they both detected the same region of the image!”
You’re right. They did.
But watch what happens when I add a single bright pixel to the top-center part of this image when you issue this command:
$ python bright.py --image images/retina-noise.png --radius 41
Your results should look something like:
Now, the naive cv2.minMaxLoc
method finds this white pixel. Let’s be clear. The function is working correctly. It is indeed finding the single brightest pixel in the entire image.
However, this really isn’t what we want.
We are interested in the brightest region of the image, which is the optic nerve center.
Luckily, by utilizing a Gaussian blur, we are able to average a neighborhood of pixels within a given radius, and thus discard the single bright pixel and narrow in on the optic center region without an issue.
Obviously, a big aspect of getting the robust method to work correctly is properly setting your radius
size. If your radius
size is too small, you won’t be able to find larger, brighter regions of the image.
But if you set the radius
size too large, then you’ll be detecting too large of regions, missing out on the smaller ones, leading to sub-par results.
Definitely spend some time playing with the radius
size and viewing the results.
What's next? We recommend PyImageSearch University.
84 total classes • 114+ hours of on-demand code walkthrough videos • Last updated: February 2024
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled
I strongly believe that if you had the right teacher you could master computer vision and deep learning.
Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?
That’s not the case.
All you need to master computer vision and deep learning is for someone to explain things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to change education and how complex Artificial Intelligence topics are taught.
If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to successfully and confidently apply computer vision to your work, research, and projects. Join me in computer vision mastery.
Inside PyImageSearch University you'll find:
- ✓ 86 courses on essential computer vision, deep learning, and OpenCV topics
- ✓ 86 Certificates of Completion
- ✓ 115+ hours of on-demand video
- ✓ Brand new courses released regularly, ensuring you can keep up with state-of-the-art techniques
- ✓ Pre-configured Jupyter Notebooks in Google Colab
- ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
- ✓ Access to centralized code repos for all 540+ tutorials on PyImageSearch
- ✓ Easy one-click downloads for code, datasets, pre-trained models, etc.
- ✓ Access on mobile, laptop, desktop, etc.
Summary
In this blog post I showed you why it is critical to apply Gaussian blurring prior to finding the brightest spot in an image.
By applying a Gaussian blur, you are averaging the pixels within a given radius of each other together. Taking the average allows you to remove high frequency noise that would have otherwise thrown off the results of the cv2.minMaxLoc
function.
Be sure to explore appropriate values for the radius of Gaussian blur. If you take too small of a value, you’ll mitigate the effects of the average and miss out on the larger, brighter regions. But if your radius is too large, you won’t detect the small bright regions.
Download the Source Code and FREE 17-page Resource Guide
Enter your email address below to get a .zip of the code and a FREE 17-page Resource Guide on Computer Vision, OpenCV, and Deep Learning. Inside you'll find my hand-picked tutorials, books, courses, and libraries to help you master CV and DL!
Jeremy
Hi Adrian,
Nice tutorial. However I think there is a different approach (more similar to finding the brightest pixel) that may also work, without having to write your own method.
Step 1: filter the image using a Gaussian or median filter (median is best for salt-and-pepper noise)
Step 2: find the brightest pixel the less-robust way
That said, I like your method better. However, I think that usually when people learn to find peaks, they have it drilled into them to filter first, for exactly this reason!
Adrian Rosebrock
Hi Jeremy, thank you for commenting. Great point — using a filter prior to finding the brightest pixel is a good idea. Given that this is an introductory post, I think using the Gaussian blur is a better idea and easier to understand. I’m going to go back and update the post.
Ahmed
Hello Adrian, Great to see the post! I want to detect the hot point in my thermal Video. How can I get the exact temperature and is there any method to compare two videos according to the characteristics?
Sorry to ask this, I am learning tutorials but a new one to Python. Thanks
Adrian Rosebrock
If you are using the same thermal sensor to capture the temperatures (and therefore know what temperatures of various color bands are) then yes, it would be possible. This solution would involve color thresholding.
EmmaG
Hey Adrian,
Nice example ! I am working on something similar like draw circle only if the bright spot found.
Else no circle.One way is to use threshold, if min_val < threshold then draw rectangle. But in my case i am not able to decide threshold values between 0-1.my min max values are something like 221462064.0 and 758624512.0 respectively.I want to work this for other images too.
Can u show how can i do it or may be some other method to do it?
Adrian Rosebrock
Hi Emma. You could always scale your values into the range [0, 1] first by dividing my the maximum value that occurs in your image. But not really wouldn’t be a fix. It seems like you are trying to accomplish some sort of adaptive thresholding based on the brightest parts of the image. Without seeing your images (and getting more details), I can’t really provide a solution to the problem.
Azrael
Hello Adrian,
Thanks for the post.
Can you tell me how to find out the darkest region in the image, but only within the circle(eye)?
And do you have any thoughts on using kernels to find the darkest and brightest regions of the image? How would you do that?
I believe using a kernel would greatly help in removing any errors.
Adrian Rosebrock
Hi Azrael, to find the darkest region of the image simply take a look at the
minVal
andminLoc
values. And to only find the regions within the actual eye, you just need to specify the ROI (Region of Interest) that you want to investigate — which is in this case the eye. Take a look at this blog post on OpenCV basics to learn how to crop the image. You can then take this cropped image and find the min/max values.Also, a Gaussian kernel (for blurring) has already been applied (Line 28) to the image prior to finding the min/max values. This helps reduce noise and improve results.
Tuhin
If I want to find the mean intensity of the brightest region of an image
then how would I do that ??
Thankx in advance
Adrian Rosebrock
Hi Tuhin. If you want to find the mean intensity of the brightest region of the image, you could use
cv2.minMaxLoc
as I did in the example. Then you would extract an M x N pixel region surrounding the brightest region. And then callcv2.mean
on that region — that will give you the mean intensity of the brightest region.Tuhin
How should I extract MxN region ?
How to find the values of M an N?
Thanx again!!
Adrian Rosebrock
You need to determine the values of M and N yourself. For example, you could extract a 20 x 20 pixel region, a 10 x 10 pixel region, etc. That decision is entirely up to you. Take a look at this post to learn more about cropping and extracting regions from images. I would also suggest taking a look a my book, Practical Python and OpenCV. It will definitely help jumpstart your OpenCV education! Cheers.
Tuhin
Hey!! thankx a bunch!!!
Miash
Sorry to ask stupid question, because i’m a newbie in python and opencv…
I would like to ask if the method mentioned above can be applied to a live feed video in the previous tutorial “Accessing the Raspberry Pi Camera with OpenCV and Python”.
Adrian Rosebrock
It certainly can! You just need to update the Accessing Raspberry Pi Camera code, specifically the
for
loop where the frames are being accessed, to apply the techniques proposed in this post.Vishal
Hey Adrian. Could you please explain in detail on how to set this code up for a live video tracking ??
Adrian Rosebrock
It depends on what type of camera you are using (webcam or Raspberry Pi camera module), but the gist is that you should start with this blog post and then use it as a template to access your webcam. From there, detect the brightest region in each frame.
vin
hi adrian!
i understand why blurring works in this specific instance. would there be any instances where you simply filtered by size? (eg, find pixels above a certain value and then simply ignore anything less than N pixels).
thanks!
Adrian Rosebrock
Certainly! A great example is in this post on target detection. Notice how I ignore any regions of the image that are smaller than 25×25 pixels.
Brian
Hi Adrian,
I tried the above code verbatim but encountered the following error:
AttributeError: ‘Nonetype’ object has no attribute ‘copy’
Why not use: orig = image?
Also, must the image be PNG format or will any other format work such as JPG, BMP, etc.?
Thanks,
-Brian
Adrian Rosebrock
If you’re getting an error related to the image being
None
, then your image is not being properly loaded from disk via thecv2.imread
function or the path supplied thecv2.imread
is not valid. OpenCV comes with built-in support for reading BMP images, but you need to install the appropriate JPEG and PNG libraries for your system prior to compiling and installing OpenCV.Vishal
can you explain on how to remove debug this error now ??
Adrian Rosebrock
What is your error?
Brian
Adrian,
Great tutorial!
When I copied your code verbatim I encountered an error with image.copy(). I was able to get around it by simply replacing this line of code with: orig = image. I’m using OpenCV 3.0.0 so I’m not sure if that was the issue. I thought I should post this to help anyone else who might be having the same issue.
Digging a little deeper, I didn’t quite understand the purpose of making a copy of the image. I commented out the image.copy lines of code completely and the program seems to work just fine. Can you add some detail as to what the image copy was for?
One final note, I’d would highly recommend adding to this tutorial:
cv2.imshow(“Gray”, gray)
This certainly helped me to understand what was happening during the Gaussian blur process as the radius changes.
Thanks again for the great tutorials!
-Brian
Adrian Rosebrock
The
.copy()
method is used to make a deep copy (rather than a shallow copy) of the image. This allows us to “draw” the circles on two separate images and display our results. If you’re using this code in an image processing pipeline, you can certainly leave it out.Angel John Babasa
Hi! Is it possible to detect multiple bright spots in an image and find their pixel coordinates? thanks!
Adrian Rosebrock
Indeed, it is possible! I plan on covering it in a future blog post, but in the meantime, take a look at this tutorial with scikit-image.
TimTom
I’d be really interested in such a tutorial as well.
YaddyVirus
Hi Ardian! Nice tutorial there, really helpful tutorial. I am working on a project that requires a raspberry pi doing image processing and finding a traffic light. Once its been found, monitor it until it goes off, and as soon as it does, send appropriate commands to the Arduino(which controls motors). Now since at the moment I don’t have a RPi, I’m writing the code on my PC(Windows 8.1), the PC version of my code, detects a light from the frames captured from my Webcam, and when the light goes off, display a message on the screen, when it comes back on, display the corresponding message.
I plan to convert the video captured from the webcam into greyscale and then finding the brightest spot(hopefully the light). Now can you please tell me how to display a message (and send command to Arduino too of course), based upon the detected status of the light?
I’m new to Both OpenCV and Python, but I’ve been coding in other languages so thats not a problem. I’ve literally spent entire nights reading up the OpenCV documentation(I was initially writing the code in C++, but realized that I should switch to python as ultimately I have to use this on a RPi) and writing code. I’m in real need if help!
Thanks!
Adrian Rosebrock
Your project sounds very cooL! However, I have never done any Arduino-based development before, so I’m unfortunately not the right person to ask regarding this question. In the future, I’ll try to do more GPIO and Arduino posts that cover computer vision topics as well.
YaddyVirus
Okay fine, no problem. Anyways if not Arduino based, can you tell me how to display the corresponding message depending upon the status of the brightest spot(the light being on or off) simply in python?
Thanks again for such a nice tutorial.
YaddyVirus
And yeah, is there any way to make a trackbar to control the Guassian blur radius? Like there are in C++ Visual Studio tutorials for OpenCV object detection based on color where they convert the image to HSV and then control the H,S and V values with trackbars until they get the required binary output in the resultant window. I’m thinking that controlling the Guassian blur with a trackbar would be a good idea as in my case I’m working with a live video feed from my webcam. What do you think?
Thanks
YaddyVirus
Hi Adrian! Sorry to harass you with so many comments, but I thought I’ll post back with my most recent experiment towards my project. Okay so I did a bit of modification to your code and got the bright spot detection to work from my webcam feed. I ran the test in a room brightly lit and detected LEDs of a spare webcam I had lying around. It was quite successful(just while testing with some extreme angles it detected the collar of my white shirt as the brightest spot). Any ways, since I have to do the actual detection in sunlight, will this method work? I mean I don’t want my robot to see any other “bright spots” other than the traffic light just before a race is about to start. I can’t experiment right now as its night here in world.
Also, in my previous comment on my previous reply I thought that using a trackbar for applying Guassian blur would be better as it would give me more control over what gets detected. Can that be done? (For some reason I saw that that comment has disappeared.)
Adrian Rosebrock
All comments have to be manually approved by me, so please make sure you consolidate your comments whenever possible.
To address your questions, yes, you can create track-bars to manually control the Gaussian blur radius. Please see the range-detector script for an example of using a trackbar.
As for changing your lighting conditions, that is entirely dependent on your environment. You won’t know until you try. But in short, if there is a brighter spot in your image (brighter than the LEDs), then yes, the code will (incorrectly) detect the brighter object. In that case, you need to build extra logic into your code to prune the false-positive cases. I would suggest looking into color thresholding and contour properties (solidity, extent, aspect ratio, etc.) to prune these regions.
YaddyVirus
Well thanks for the reply. So what if I convert the image to HSV instead of grayscale and then adjust the HSV values and apply hough transform to find circles? Once all circles are found, find the brightest circle using this method ( but this method only works for single channel images if I’m right.)
Also, which language you suggest using for this project on the Raspberry Pi? C++ or Python? I’ve written the code for both languages (to the point where I can find out the required object by thresholding the image.)
Thanks! You’re a great help buddy!
Adrian Rosebrock
If you can use the HSV color space to help filter your object, then yes, absolutely do that. You’ll likely need to experiment with this approach and see if you can filter each channel or use something like cv2.inRange to filter for a specific color. And yes, this method is intended for use on single channels, but if you can filter out extraneous regions and then only examine the Value channel (which will store the intensity of the color), then you can get around this problem.
As for using Python or C++, I nearly always suggest prototyping in Python and then only coding in C++ if absolutely necessary.
YaddyVirus
Very well, sounds like a plan. Now the only question that remains is , since I don’t know how to do this in either Python or C++, how do I display a message on the screen once the desired circle(the traffic light) goes off(or comes back on)?
And yeah what to you mean by “coding in C++ if absolutely necessary”.
Thanks!
Adrian Rosebrock
What do you mean by “display a message on the screen”? You could use the
print
statement/function to write text to the terminal or you could usecv2.putText
to draw a message on the actual image.YaddyVirus
Well displaying a message in the sense that as soon as the detected spot goes black in my binary image, show a message on the screen. What’s the statement for that?
Thanks!
Adrian Rosebrock
Please see my previous comment — use either the
print
statement/function orcv2.putText
.YaddyVirus
Yeah that print statement is fine.
But there should be some condition checking statement there too, right? Like if (*as long as light is detected*). How do I check for the “visibility” of the light? Or, if no conditional check is required, where do I write the print statement?
P.S – sorry I’m still new to Python, so I’m not much proficient with the basics yet, but I’m learning! All thanks to you!
Adrian Rosebrock
Yes, a conditional is required to determine if there is sufficient light. You’ll need to program that logic yourself. Normally you would be looking for a large enough region in an image (based on width and height) that has the pixel intensity you’re looking for. If you’re still getting used to Python + OpenCV, you should absolutely work through Practical Python and OpenCV to help you get up to speed quickly.
Sanira
Hi Adrian ,
Great tutorial..!! thanks a lot for sharing your knowledge. 🙂
Adrian Rosebrock
I’m glad you found it useful Sanira! 🙂
Richie Close
Hi Adrian
Thanks for the tutorial – a great introduction to this area! I’ve a couple of questions.
What does the radius value refer to? Is it pixels?
What would be the best way to find the 6 (for example) brights area’s on an image? Could you set a brightness target threshold and search for that (along with the radius value)?
Thanks again
Richie
Adrian Rosebrock
The radius is the size (in pixels) of the Gaussian blur. The smaller the radius, the less blur. The larger the radius, the more blur. As for finding multiple bright spots in an image I actually have a blog post scheduled for that. It will be published late October/early November so be sure to keep an eye out!
kiran
in the cursor control system,
the first step was to have robust hand skin detection.
the image frames from webcam i have converted to HSV and ycbcr colour space,applied morphological operations on individual hsv and ycbcr thresholded images.
and combined both images.
thing is that i need to detect only hand skin rest such as face and some body part need to be removed ,
could you suggest me how to remove non- hand skin regions.
Adrian Rosebrock
I would suggest detecting the hand first. You might need to apply other methods than just color thresholding such as object detection. I would also suggest contour extraction and filtering only the hand regions.
Saurav
hey thanks for the tutorial but i want to know how will you issue the command in cmd like how will you give arguments.
sorry for the question but i m a beginner.
Adrian Rosebrock
Hi Saurav — You’re welcome. I suggest you read this tutorial on command line arguments.
Moorthy
i have one small help how to find the crop the brightest region on your code please help me .
Adrian Rosebrock
You can extract the region using basic NumPy array slicing.
Nayan
i like to extract the logo from an image. can i apply this Gaussian blur method to get the logo. Or is there any other method.
I will be highly grateful if you please let me know.
Adrian Rosebrock
You should look into object detection methods as well as keypoint detection and keypoint matching. I would suggest reading through Practical Python and OpenCV to learn more about keypoint matching and then Deep Learning for Computer Vision with Python to learn more about deep learning-based object detection.
Manavendra
Hi Adrian,
I am working on a project using rasberrypi and rasberrypi camera where I am blinking a led at certain frequency and their are other Led lights which are continuously on ,so is it possible to frame by frame check (process) the frames simultaneously and circle the blinking led in the video as the video is static ( the position of the led is not changing for 1 complete video ) I am going to keep the frequency of the led and the fps of the video equal so checking (processing) frames will not be a problem , as I think the led will locate maxval in one frame and minval in second frame for the same location so is there any method to locate the blinking led with highlighting circle in real time .
And last but not the least thanks for such great tutorials
I would be really grateful if you you can help me for the above problem
Adrian Rosebrock
If the position of the LED is fixed and non-moving why not just monitor that specific area of the video frame? You could compute the mean value of the region and if it’s above a pre-defined threshold the LED is “on”, otherwise it’s “off”.
Manavendra
The position of the led is fixed but it’s unknown to the user initially and we have to spot the blinking led in all other lights using pi camera….. that’s the project all about
Adrian Rosebrock
Got it, I understand now. One way to frame this problem is via motion detection/background subtraction. Since all LEDs will be “on” and only the blinking one changes, you can monitor the frames for changes in background which in turn give you the ROI of the blinking LED. I hope that helps!
shincheng
$ python bright.py –image images/retina-noise.png –step 41
small typo
–step 41 should be –radius 41
nice introduction
Adrian Rosebrock
Thank you for pointing that out! I’ve updated the post 🙂
esha
hello sir
how can we extract the region of an image consist of brightest pixels in its dark channel.
Adrian Rosebrock
You could use NumPy array slicing to extract the region — or perhaps I’m misunderstanding your question?
esha
actually sir i want a region in an image consisits of brighest pixels in its dark channel.
Isaac
Hi Adrian, thanks for this. I have a question though. How do i locate the center of the brightest “spot” within the cirlce and possible use a dot to visually indicate that?
Adrian Rosebrock
You would compute the centroid of the circle and then use the “cv2.circle” function to draw the dot. I cover both of those techniques inside Practical Python and OpenCV. I would highly suggest you start there.
Nitin rai
Hey i applied same trick to calculate overall brightness of an image.. i hope this link
https://github.com/imneonizer/How-to-find-if-an-image-is-bright-or-dark/blob/master/README.md
would help you out understanding the same.
In this blog i have explained how i divided the image into smaller segments and find brightness in those segments and finally took the average of all those calculated brightness to get the brightness level of image
It can easily tell which images are brighter and which are dark.
Hope it could help you with something.
Chong You Wang
Thanks so much for the tutorial. I have some question. If I want to detect multiple bright spot from some PET/CT image and classified it to folder(have bright spot or no bright spot). How should I do?