Skip to content

Commit 0b70d4c

Browse files
committed
image-processing algos added | Updated ReadMe | added CONTRIBUTING.md | .gitignore
1 parent a3a87f2 commit 0b70d4c

19 files changed

+348
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.history
2+
.dist

CONTRIBUTING.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Contributing guidelines
2+
3+
## Before contributing
4+
5+
Welcome to [TheAlgorithms/MATLAB-Octave](https://github.com/TheAlgorithms/MATLAB-Octave.git)! Before sending your pull requests, make sure that you **read the whole guidelines**. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/MATLAB-Octave/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms).
6+
7+
### Contributor
8+
9+
We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
10+
11+
- You did your work - no plagiarism allowed
12+
- Any plagiarized work will not be merged.
13+
- Your work will be distributed under [MIT License](License) once your pull request is merged
14+
- You submitted work fulfils or mostly fulfils our styles and standards
15+
16+
**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity.
17+
18+
**Improving comments** and **writing proper tests** are also highly welcome.
19+
20+
When contributing to this repository, please first discuss the change you wish to make via issue,
21+
email, or any other method with the owners of this repository before making a change.
22+
23+
Please note we have a code of conduct, please follow it in all your interactions with the project.
24+
25+
## Pull Request Process
26+
27+
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
28+
build.
29+
2. Update the README.md with details of changes to the interface, this includes new environment
30+
variables, exposed ports, useful file locations and container parameters.
31+
3. Increase the version numbers in any examples files and the README.md to the new version that this
32+
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
33+
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
34+
do not have permission to do that, you may request the second reviewer to merge it for you.
35+
36+
## Code of Conduct
37+
38+
### Our Pledge
39+
40+
In the interest of fostering an open and welcoming environment, we as
41+
contributors and maintainers pledge to making participation in our project and
42+
our community a harassment-free experience for everyone, regardless of age, body
43+
size, disability, ethnicity, gender identity and expression, level of experience,
44+
nationality, personal appearance, race, religion, or sexual identity and
45+
orientation.
46+
47+
### Our Standards
48+
49+
Examples of behavior that contributes to creating a positive environment
50+
include:
51+
52+
* Using welcoming and inclusive language
53+
* Being respectful of differing viewpoints and experiences
54+
* Gracefully accepting constructive criticism
55+
* Focusing on what is best for the community
56+
* Showing empathy towards other community members
57+
58+
Examples of unacceptable behavior by participants include:
59+
60+
* The use of sexualized language or imagery and unwelcome sexual attention or
61+
advances
62+
* Trolling, insulting/derogatory comments, and personal or political attacks
63+
* Public or private harassment
64+
* Publishing others' private information, such as a physical or electronic
65+
address, without explicit permission
66+
* Other conduct which could reasonably be considered inappropriate in a
67+
professional setting
68+
69+
### Our Responsibilities
70+
71+
Project maintainers are responsible for clarifying the standards of acceptable
72+
behavior and are expected to take appropriate and fair corrective action in
73+
response to any instances of unacceptable behavior.
74+
75+
Project maintainers have the right and responsibility to remove, edit, or
76+
reject comments, commits, code, wiki edits, issues, and other contributions
77+
that are not aligned to this Code of Conduct, or to ban temporarily or
78+
permanently any contributor for other behaviors that they deem inappropriate,
79+
threatening, offensive, or harmful.
80+
81+
### Scope
82+
83+
This Code of Conduct applies both within project spaces and in public spaces
84+
when an individual is representing the project or its community. Examples of
85+
representing a project or community include using an official project e-mail
86+
address, posting via an official social media account, or acting as an appointed
87+
representative at an online or offline event. Representation of a project may be
88+
further defined and clarified by project maintainers.
89+
90+
### Enforcement
91+
92+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
93+
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
94+
complaints will be reviewed and investigated and will result in a response that
95+
is deemed necessary and appropriate to the circumstances. The project team is
96+
obligated to maintain confidentiality with regard to the reporter of an incident.
97+
Further details of specific enforcement policies may be posted separately.
98+
99+
Project maintainers who do not follow or enforce the Code of Conduct in good
100+
faith may face temporary or permanent repercussions as determined by other
101+
members of the project's leadership.

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
# MATLAB / Octave
1+
# MATLAB / Octave ![](https://img.shields.io/github/forks/TheAlgorithms/Jupyter?style=social) ![](https://img.shields.io/github/stars/TheAlgorithms/Jupyter?style=social) ![](https://img.shields.io/github/watchers/TheAlgorithms/Jupyter?style=social) <br>
2+
3+
![](https://img.shields.io/github/repo-size/TheAlgorithms/Jupyter) ![](https://img.shields.io/github/downloads/TheAlgorithms/Jupyter/total)<br>
4+
![](https://img.shields.io/github/issues/TheAlgorithms/Jupyter?color=green) ![](https://img.shields.io/github/issues-pr/TheAlgorithms/Jupyter?color=green) ![](https://img.shields.io/github/last-commit/TheAlgorithms/Jupyter) ![](https://img.shields.io/github/contributors/TheAlgorithms/Jupyter)
25

36
These repository is a collection of useful algorithms and data structures built in MATLAB/Octave. In addition you will find solutions from project euler problem sets. The code in this repository is cross-portabel for MATLAB and for Octave.
47

58
### What is Octave?
69

710
[Octave](https://www.gnu.org/software/octave/) is a free high-level interpreter language that is equivalent to the textuelle programming language MATLAB.
811

12+
## Clone git repository
13+
14+
```sh
15+
$ git clone "https://github.com/TheAlgorithms/MATLAB-Octave.git"
16+
```
17+
18+
You can run and edit the algorithms or contribute to them using [Gitpod.io](https://www.gitpod.io/), a free online development environment, with a single click.
19+
20+
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](http://gitpod.io/#https://github.com/TheAlgorithms/MATLAB-Octave)
21+
22+
23+
924
### Overview about this repository
1025

1126
---
@@ -39,10 +54,17 @@ These repository is a collection of useful algorithms and data structures built
3954
* nearest neighbor
4055
* brightness (recognizes the brightness of a color)
4156
* k-means clustering
42-
57+
58+
* image-processing
59+
* Blob-detection
60+
4361

4462
---
4563

4664
### Contributing
4765

4866
You can like contribute to this repository. You simply orient on the directory structure.
67+
68+
## License
69+
70+
Licensed under the [MIT License](LICENSE)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
%% read the frame
2+
3+
cap = vision.VideoFileReader('multiple_ball.avi');
4+
cap.VideoOutputDataType = 'double';
5+
6+
%% reduce noise by using opening
7+
8+
noise = strel('disk',3);
9+
10+
%% blob analysis
11+
12+
% to perform a blob analysis on the video frame we need to use step
13+
% function :- parameter => (blob analysis system object , input image i.e open)
14+
% function output 3 :- area , centroid , bounding box
15+
16+
blob = vision.BlobAnalysis('MinimumBlobArea',200,...
17+
'MaximumBlobArea',5000);
18+
19+
% Create VideoPlayer
20+
vidPlayer = vision.DeployableVideoPlayer;
21+
22+
%% while True
23+
while ~isDone(cap)
24+
25+
% Read Frame
26+
frame = step(cap);
27+
28+
% Convert RGB image to HSV
29+
hsv = rgb2hsv(frame);
30+
31+
% Define thresholds for channel 1 based on histogram settings
32+
channel1Min = 0.398;
33+
channel1Max = 0.498;
34+
35+
% Define thresholds for channel 2 based on histogram settings
36+
channel2Min = 0.355;
37+
channel2Max = 1.000;
38+
39+
% Define thresholds for channel 3 based on histogram settings
40+
channel3Min = 0.000;
41+
channel3Max = 1.000;
42+
43+
% Create mask based on chosen histogram thresholds
44+
Ibw = (hsv(:,:,1) >= channel1Min ) & (hsv(:,:,1) <= channel1Max) & ...
45+
(hsv(:,:,2) >= channel2Min ) & (hsv(:,:,2) <= channel2Max) & ...
46+
(hsv(:,:,3) >= channel3Min ) & (hsv(:,:,3) <= channel3Max);
47+
48+
% Use morphological operations to remove disturbances
49+
opening = imopen(Ibw,noise);
50+
51+
% Extract the blobs from the frame
52+
[object_area,object_centroid,bounding_box] = step(blob, opening);
53+
54+
% Draw a box around the detected objects
55+
Ishape = insertShape(frame,'Rectangle',bounding_box);
56+
57+
% Insert a string of number of objects detected in the video frame.
58+
59+
numObj = length(object_area);
60+
61+
%Itext = step(hTextIns,Ishape,int32(numObj));
62+
63+
%Play in the video player
64+
%step(vidPlayer, Itext);
65+
step(vidPlayer, Ishape);
66+
67+
68+
end
69+
70+
%% Clean
71+
72+
release(cap)
73+
release(blob)
74+
%release(hTextIns)
75+
release(vidPlayer)
Loading
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
## Blob detection and analysis using Matlab
2+
A Blob is a group of connected pixels in an image that share some common property ( E.g grayscale value ).
3+
4+
### Steps includes for blob analysis on image
5+
6+
> ### Load sample frames
7+
8+
```matlab
9+
10+
load sampleFrames.mat
11+
subplot(1,3,1)
12+
imshow(vidFrame1)
13+
```
14+
> ### Threshold image
15+
```matlab
16+
I = rgb2hsv(vidFrame1);
17+
18+
% Define thresholds for channel 1 based on histogram settings
19+
channel1Min = 0.333;
20+
channel1Max = 0.561;
21+
22+
% Define thresholds for channel 2 based on histogram settings
23+
channel2Min = 0.327;
24+
channel2Max = 1.000;
25+
26+
% Define thresholds for channel 3 based on histogram settings
27+
channel3Min = 0.186;
28+
channel3Max = 1.000;
29+
30+
% Create mask based on chosen histogram thresholds
31+
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
32+
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
33+
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
34+
BW = sliderBW;
35+
36+
subplot(1,3,2)
37+
imshow(BW)
38+
39+
40+
```
41+
> ### Remove disturbances
42+
```matlab
43+
44+
noise = strel('disk' , 3);
45+
46+
open = imopen(BW, noise);
47+
subplot(1,3,3);
48+
imshow(open);
49+
50+
```
51+
> ### Blob Analysis
52+
53+
```matlab
54+
blob = vision.BlobAnalysis('MinimumBlobArea',200,...
55+
'MaximumBlobArea',5000);
56+
% to perform a blob analysis on the video frame we need to use step
57+
% function :- parameter => (blob analysis system object , input image i.e open)
58+
% function output 3 :- area , centroid , bounding box
59+
60+
[objectArea , objCentroid , bboxout] = step(blob , open);
61+
62+
63+
```
64+
> ### Annotate image
65+
```matlab
66+
67+
% now we get a bounding box cordinates of detected ball let apply contour
68+
% over the detected ball using rectangle
69+
70+
rectangle = insertShape(vidFrame1 , 'rectangle',bboxout , 'Linewidth' , 4 , 'Color',...
71+
[155 164 155]);
72+
73+
figure
74+
subplot(1,2,1)
75+
imshow(rectangle)
76+
77+
78+
```
79+
> ### Clean up
80+
81+
```matlab
82+
release(blob)
83+
84+
```
85+
86+
### Result
87+
88+
![](Media2.gif "Blob Detection using Matlab")
89+
Binary file not shown.
Loading
Loading
Loading
Loading
Loading
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
% Copyright 2014-2015 The MathWorks, Inc.
2+
%% Load sample frames
3+
load sampleFrames.mat
4+
subplot(1,3,1)
5+
imshow(vidFrame1)
6+
7+
%% Threshold image
8+
% Convert RGB image to chosen color space
9+
I = rgb2hsv(vidFrame1);
10+
11+
% Define thresholds for channel 1 based on histogram settings
12+
channel1Min = 0.379;
13+
channel1Max = 0.496;
14+
15+
% Define thresholds for channel 2 based on histogram settings
16+
channel2Min = 0.436;
17+
channel2Max = 1.000;
18+
19+
% Define thresholds for channel 3 based on histogram settings
20+
channel3Min = 0.000;
21+
channel3Max = 1.000;
22+
23+
% Create mask based on chosen histogram thresholds
24+
BW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
25+
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
26+
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
27+
28+
subplot(1,3,2)
29+
imshow(BW)
30+
31+
%% Remove disturbances
32+
diskElem = strel('disk',3);
33+
Ibwopen = imopen(BW,diskElem);
34+
subplot(1,3,3)
35+
imshow(Ibwopen)
36+
37+
%% Blob Analysis
38+
hBlobAnalysis = vision.BlobAnalysis('MinimumBlobArea',200,...
39+
'MaximumBlobArea',5000);
40+
[objArea,objCentroid,bboxOut] = step(hBlobAnalysis,Ibwopen);
41+
42+
%% Annotate image
43+
Ishape = insertShape(vidFrame1,'rectangle',bboxOut,'Linewidth',4);
44+
figure
45+
subplot(1,2,1)
46+
imshow(Ishape)
47+
48+
numObj = numel(objArea);
49+
hTextIns = vision.TextInserter('%d','Location',[20 20],'Color',...
50+
[255 255 0],'FontSize',30);
51+
Itext = step(hTextIns,Ishape,int32(numObj));
52+
subplot(1,2,2)
53+
imshow(Itext)
54+
55+
%% Clean up
56+
release(hBlobAnalysis)
57+
release(hTextIns)

0 commit comments

Comments
 (0)