Friday, 18 July 2014

To find transpose of an image

for i=1:512
   for j=1:512
    B(j,i)=A(i,j);
 end
end


Vertical Flip

for i=1:512
   for j=1:512
    B(i,512+1-j)=A(i,j);
 end
end

Image Cropping

for k=0:64-1
    for l=0:128-1
        B(k+1,l+1)=A(255+k+1,255+l+1);
  end
end
 

Thursday, 17 July 2014

detect people in matlab

peopleDetector = vision.PeopleDetector;
I = imread('visionteam1.jpg');
[bboxes, scores] = step(peopleDetector, I);
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[255 255 0]);
 scoreInserter = vision.TextInserter('Text',' %f','Color', [0 80 255],'LocationSource','Input port','FontSize',16);
I = step(shapeInserter, I, int32(bboxes));
 I = step(scoreInserter, I, scores, int32(bboxes(:,1:2)));
figure, imshow(I)
title('Detected people and detection scores'); 

how to detect cars in an image taken from real time

foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
    'NumTrainingFrames', 50);

videoReader = vision.VideoFileReader('visiontraffic.avi');
for i = 1:150
    frame = step(videoReader); % read the next video frame
    foreground = step(foregroundDetector, frame);
end
figure; imshow(frame); title('Video Frame');
figure; imshow(foreground); title('Foreground');
se = strel('square', 3);
filteredForeground = imopen(foreground, se);
figure; imshow(filteredForeground); title('Clean Foreground');
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
    'AreaOutputPort', false, 'CentroidOutputPort', false, ...
    'MinimumBlobArea', 150);
bbox = step(blobAnalysis, filteredForeground);
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
    'FontSize', 14);
figure; imshow(result); title('Detected Cars');

Wednesday, 16 July 2014

how to reduce image using Gaussian Pyramid Decomposition

The image reduction step involves lowpass filtering and downsampling the image pixels. The image expansion step involves upsampling the image pixels and lowpass filtering.


Example
gaussPyramid = vision.Pyramid('PyramidLevel', 2);
I = im2single(imread('cameraman.tif'));                 
J = step(gaussPyramid, I);
figure, imshow(I); title('Original Image');
figure, imshow(J); title('Reduced Image');

Monday, 14 July 2014

Useful System Objects for Video File I/O, Display, and Graphics

Useful System Objects for Video File I/O,  Display, and Graphics

File I/O
–VideoFileReader
–VideoFileWriter

Display
–VideoPlayer
–DeployableVideoPlayer

Graphics
–AlphaBlender
–MarkerInserter
–ShapeInserter
–TextInserter

Preprocessing
–ChromaResampler
–Deinterlacer
–DemosaicInterpolator

Statistics (running across video frames)
–Histogram
–Maximum
–Mean
–Median
–Minimum
–StandardDeviation
–Variance

how to count number of cells in image

a=imread('normal.jpg');
[m n p]=size(a);
 r=a(:,:,1);
 g=a(:,:,2);
 b=a(:,:,3);
for i=1:m
    for j=1:n
        for k=1:p
        if (r(i,j)>200)||(g(i,j)>160)||(b(i,j)>200)
      d(i,j)=0;
  else
      d(i,j)=a(i,j);
        end
    end
    end
end
imshow(d);
b=imcomplement(d);
figure,imshow(b);
[l num]=bwlabel(b,4);
figure,disp(l);
for i=1:num
    imshow(l==i);
   % pause(1);
 end



roipoly command in matlab

a=imread('data1.jpg');
[m n]=ginput(1);
bw=roipoly(a,m,n);
figure,imshow(bw);
[M N]=size(bw);
for i=1:m
 for j=1:n
    if bw(i,j)==1
       b(i,j)=a(i,j);
   else
      b(i,j)=0;
   end
end
end
figure,imshow(b,[]);title('output image');