IPMV
IPMV
IPMV
PROJECT
AIM:-TO DETECT RED COLOR FROM AN IMAGE USING
MATLAB SOFTWARE
SOFTWARE REQUIRED:-MATLAB2019a
THEORY:-
Gray-scale Images:-
.A gray-scale image is a data matrix whose values represent
shades of gray. When the elements of a gray-scale image are
of class uint8 or uint16, they have integer values in the range
[0, 255] or [0, 65535], respectively. If the image is of class
double or single, the values are floating-point numbers.
Values of double and single gray-scale images normally are
scaled in the range [0, 1], although other ranges can be used
Binary Images:-
Binary images have a very specific meaning in MATLAB. A
binary image is a logical array of 0s and 1s. Thus, an array of
0s and 1s whose values are of data class, say, uint8, is not
considered a binary image in MATLAB. A numeric array is
converted to binary using function logical. Thus, if A is a
numeric array consisting of 0s and 1s, we create a logical
array B using the statement
B = logical(A)
If A contains elements other than 0s and 1s, the logical
function converts all nonzero quantities to logical 1s and all
entries with value 0 to logical 0s. Using relational and logical
operators (see Section 2.10.2) also results in logical arrays.
To test if an array is of class logical we use the islogical
function:
islogical(C)
If C is a logical array, this function returns a 1. Otherwise it
returns a 0. Logical arrays can be converted to numeric arrays
using the class conversion functions.
Indexed Images:-
An indexed image consists of a data matrix, X, and a
colormap matrix, map. map is an m-by-3 array of class double
containing floating-point values in the range [0, 1]. Each row
of map specifies the red, green, and blue components of a
single color. An indexed image uses “direct mapping” of pixel
values to colormap values. The color of each image pixel is
determined by using the corresponding value of X as an index
into map. Values of X therefore must be integers. The value 1
points to the first row in map, the value 2 points to the second
row, and so on.
RGB (Truecolor) Images:-
An RGB image, sometimes referred to as a truecolor image, is
stored as an m-by-n-by-3 data array that defines red, green,
and blue color components for each individual pixel. RGB
images do not use a palette. The color of each pixel is
determined by the combination of the red, green, and blue
intensities stored in each color plane at the pixel’s location.
Graphics file formats store RGB images as 24-bit images,
where the red, green, and blue components are 8 bits each.
This yields a potential of 16 million colors. The precision with
which a real-life image can be replicated has led to the
nickname “truecolor image.”
SIMULATION OF IMAGE:-
5. In the model, click the Run button on the toolbar to run the
simulation
In this task, you will create a new model to use the Video
Display block and deploy the model algorithm to the device
1. Open a new Simulink model and copy the contents of the
first model into the new model.
o a=imread(‘d.jpg’);
o figure(1),title(‘original image’),imshow(a);
o b=rgb2gray(a);
o red = imsubtract(a(:,:,1), b)%1 for red,2 for green ,3 for
blue
o red =medfilt2(red, [4 4]); ]); % Filter out the noise by
using median filter
To click an image:-
o vid=videoinput(‘winvideo’,1,’YUY2_320x240′);
o im=getsnapshot(vid);
o imshow(im);
o im=ycbcr2rgb(im); % the image snapped is usually in
ycbcr
o imshow(im);
o imwrite(im,’myimage.jpg’);
Looping Technique:-
o vid=videoinput(‘winvideo’);
o for i= 1:5
o set(vid,’ReturnedColorSpace’,’rgb’);
o snapshot=getsnapshot(vid);
o imshow(snapshot);
o end
v= videoinput(‘winvideo’,1,’YUY2_320x240′);
set(v,’ReturnedColorSpace’,’rgb’);
set(v,’TriggerRepeat’,Inf);
figure;
set(gcf,’doublebuffer’,’on’); % Double buffering is the
process of drawing to an off-screen pixel buffer and then
blitting the buffer contents to the screen once the drawing is
complete.
start(v)
while(v.FramesAcquired<=500)%run time =500/fps
data = getsnapshot(v);
r= imsubtract(data(:,:,1),rgb2gray(data));
r = medfilt2(r, [4 4]);
red = im2bw(r,0.17);
R = sum(red(:));
subplot(1,2,1);imshow(data);
subplot(1,2,2);imshow(red);
if(R > 0) % display red if red color is being detected
disp(‘RED’);
else
disp(‘NONE’);
end
end
stop(v);
f=bwareaopen(f,300);
bw=bwlabel(f,8);
stats=regionprops(bw,’BoundingBox’,’Centroid’);%refer
matlab help to know more about regionprops
imshow(data)
hold on
for object=1:length(stats) % Write the corresponding
centroids
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
rectangle(‘Position’,bb,’EdgeColor’,’r’,’LineWidth’,2)
plot(bc(1),bc(2))
a=text(bc(1)+15,bc(2),strcat(‘X:’,num2str(round(bc(1))),’Y’,n
um2str(round(bc(2)))));%x and y coordinate of centroid
set(a,’fontName’,’Arial’,’FontWeight’,’bold’,’FontSize’,12,’
Color’,’yellow’);
end
% Clearing Memory
flushdata(vid);
end
stop(vid)
hold off
CODE:-
data = imread('office_3.jpg');
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
imshow(data)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
hold off
CONCLUSION:-
With the help of image processing toolbox in the
MATLAB, the program had been made which can detect red,
blue, green, magenta, yellow, cyan colors. Also, the colored
object is being enclosed inside a bounded region along with
the centroid of that region.
REFERENCES:-
1.https://ch.mathworks.com/help/supportpkg/android/ref/color
-detection.html.
2. http://www.ucrjiit.com/tutorials/?p=27&i=1.
3. https://www.ijcaonline.org
4. https://www.theengineeringprojects.com
5. https://www.instructables.com