The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Sunday, May 12, 2013

Applying Blob Detection Technique to the Original Image 2



clc;
clear all;
originalImage = imread('coins.png');
subplot(3, 3, 1);
imshow(originalImage);
% Maximize the figure window.
set(gcf, 'Position', get(0, 'ScreenSize'));
[pixelCount grayLevels] = imhist(originalImage);
subplot(3, 3, 2);
bar(pixelCount); title('Histogram of original image');
xlim([0 grayLevels(end)]); % Scale x axis manually.
  thresholdValue = 100;
  binaryImage = originalImage > thresholdValue;



binaryImage = imfill(binaryImage, 'holes');
% Display the binary image.
subplot(3, 3, 3); imagesc(binaryImage); colormap(gray(256)); title('Binary Image, obtained by thresholding'); axis square;
labeledImage = bwlabel(binaryImage, 8);    
% Label each blob so we can make measurements of it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% pseudo random color labels
subplot(3, 3, 4); imshow(labeledImage, []);
title('Labeled Image, from bwlabel()');
axis square; subplot(3, 3, 5); imagesc(coloredLabels);
axis square;
caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.');
title(caption);
blobMeasurements = regionprops(labeledImage, originalImage, 'all');  
numberOfBlobs = size(blobMeasurements, 1);
subplot(3, 3, 6); imagesc(originalImage);
title('Outlines, from bwboundaries()'); axis square; hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries);

for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;


Applying Blob Detection Technique to the Original Image



clc;
clear all;
originalImage = imread('coins.png');
subplot(3, 3, 1);
imshow(originalImage);
% Maximize the figure window.
set(gcf, 'Position', get(0, 'ScreenSize'));
[pixelCount grayLevels] = imhist(originalImage);
subplot(3, 3, 2);
bar(pixelCount); title('Histogram of original image');
xlim([0 grayLevels(end)]); % Scale x axis manually.
thresholdValue = 100;
binaryImage = originalImage > thresholdValue;

binaryImage = imfill(binaryImage, 'holes');
% Display the binary image.
subplot(3, 3, 3); imagesc(binaryImage); colormap(gray(256)); title('Binary Image, obtained by thresholding'); axis square;
labeledImage = bwlabel(binaryImage, 8); 
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
subplot(3, 3, 4);              imshow(labeledImage, []);          
title('Labeled Image, from bwlabel()');
axis square;      subplot(3, 3, 5);                                
imagesc(coloredLabels);
axis square;
caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.');
title(caption);
blobMeasurements = regionprops(labeledImage, originalImage, 'all');  
numberOfBlobs = size(blobMeasurements, 1);
subplot(3, 3, 6); imagesc(originalImage);
title('Outlines, from bwboundaries()'); axis square;       hold on;
boundaries = bwboundaries(binaryImage);      
numberOfBoundaries = size(boundaries);

for k = 1 : numberOfBoundaries
              thisBoundary = boundaries{k};
              plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;

Applying Corner Detection Technique to the Original Image



I = checkerboard(50,2,2);
C = corner(I);
imshow(I);
hold on
plot(C(:,1), C(:,2), 'r*');

Applying Watershed Segmentation to the Original Image



I = imread('image.jpg');
subplot(1,2,1); imshow(I); title('Original Image');
se = strel('diamond',7);
Itop = imtophat(I,se);
Ibot = imbothat(I,se);
Ienhance = imsubtract(imadd(Itop,30), Ibot);
Iec = imcomplement(Ienhance);
Iemin = imextendedmin(Iec,22);
Iimpose = imimposemin(Iec,Iemin);
Iwat = watershed(Iimpose);
Iseg = label2rgb(Iwat);
subplot(1,2,2); imshow(Iseg); title('Watershed Segmented Image');

Applying Dilation and Erosion to the Original Image



Lenna = imread('lenna2.jpg');
SE3 = strel('square',3);
SE5 = strel('square',5);                                   
SE7 = strel('square',7);

ErodeLenna = imerode(Lenna,SE3);
subplot(2,3,1); imshow(ErodeLenna);  ylabel('Eroded Image'); title('5x5');
ErodeLenna = imerode(Lenna,SE5);
subplot(2,3,2); imshow(ErodeLenna); title('5x5');
ErodeLenna = imerode(Lenna,SE7);
subplot(2,3,3); imshow(ErodeLenna); title('7x7');

Converting Grayscale Image into Binary Image (Black-White)


Lenna = imread('lenna.png');
GrayLenna = rgb2gray(Lenna);
bwLenna = im2bw(GrayLenna);
subplot(1,2,1); imshow(bwLenna);                          
subplot(1,2,2); imhist(bwLenna)

Creating a Histogram of an Original Image



Lenna = imread('lenna.png');                                                     
GrayLenna = rgb2gray(Lenna);
imhist(GrayLenna)