Showing posts with label Connectivity. Show all posts
Showing posts with label Connectivity. Show all posts

Tuesday, March 29, 2016

Histogram Processing in MATLAB

     Read and Plot the histogram of dark, bright, Low contrast and High contrast image without using built-in function. Verify with the built-in function imhist.

       CODE :

clc; clear all;
img1=imread(
'hist1.jpg');
img2=imread(
'hist2.jpg');
img3=imread(
'hist3.jpg');
img4=imread(
'hist4.jpg');
subplot(431), imshow(img1), title(
'Dark image')
subplot(434), imshow(img2), title(
'Bright image')
subplot(437), imshow(img3), title(
'Low contrast image')
subplot(4,3,10), imshow(img4), title(
'High contrast image')

for a=2:3:11
   
if(a==2)
        img=img1;
   
elseif(a==5)
        img=img2;
   
elseif(a==8)
        img=img3;
   
else
        img=img4;
   
end

[M, N]=size(img);
histbar=zeros(1,256);
for i=1:M
   
for j=1:N
            v=img(i,j);
            histbar(v+1)=histbar(v+1)+1;
   
end
end
subplot(4,3,a), bar(histbar);
if (a==2), title('Histogram Using code'); end
subplot(4,3,a+1), imhist(img);
if (a==2), title('Histogram using Built-in function'); end
end

OUTPUT RESULT :


Friday, March 18, 2016

Connectivity in MATLAB

Create a checker board pattern and count the number of objects using 4 and 8 connectivity.

MATLAB CODE:



I=checkerboard(20);
figure,imshow(I);
[l,num]=bwlabel(I);                       % check the number of objects using 4 and 8 connectivity
RGB=label2rgb(bwlabel(I));   % Display the objects using conversion label2rgb
figure,imshow(RGB)


Checkerboard Pattern

Connected Components
CONCLUSION:

A checkerboard pattern was created and the connected objects were found using 8 - connectivity. All the connected objects were displayed using an RGB representation as shown in Fig. 1