I want to get a plot of size of circles(pixels) vs. their numbers. Example 10 of 20 pixels, 15 of 10 pixels size etc.. the background should be contrast of intensity of the circles..
MATLAB: How can i count the number of circles with random centers and fixed diameters.
Related Solutions
Convert to grayscale and then threshold and find the bounding box
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;% Read in the color image.
folder = pwd;baseFileName = 'm2.bmp';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; endendrgbImage = imread(fullFileName);% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);% Display the original color image.
subplot(2, 3, 1);imshow(rgbImage, []);axis on;title('Original Color Image', 'FontSize', fontSize);drawnow;% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Histogram the red channel, but there is a huge spike at 255 so let's not count those.
subplot(2, 3, 2);grayImage = rgb2gray(rgbImage);imshow(grayImage, []);title('Gray Scale version', 'FontSize', fontSize);subplot(2, 3, 3);histogram(grayImage(grayImage<255))grid on;title('Histogram of Gray Scale Image', 'FontSize', fontSize);someThresholdValue = 150;binaryImage = grayImage > someThresholdValue;% Take largest blob
binaryImage = bwareafilt(binaryImage, 1);subplot(2, 3, 4);imshow(binaryImage);grid on;title('Binary Image', 'FontSize', fontSize);% Label the binary image.
labeledImage = bwlabel(binaryImage);props = regionprops(labeledImage, 'BoundingBox');bbox = props.BoundingBoxcroppedImageRGB = imcrop(rgbImage, bbox);subplot(2, 3, 5);imshow(croppedImageRGB);grid on;title('Cropped RGB Image', 'FontSize', fontSize);% Gray scale version of cropped image
croppedImageGray = imcrop(grayImage, bbox);subplot(2, 3, 6);imshow(croppedImageGray);grid on;title('Cropped Gray Scale Image', 'FontSize', fontSize);
I have to detect hand from an image. First when I tried your code that is given in link below: https://www.mathworks.com/matlabcentral/answers/112917-how-to-detect-hand It was detecting my complete image as an one object, so I use skin segmentation then it detect my hand with an arm area as shown in given figure. Can you please tell me how can I detect hand from an arm.
folder=('C:\Users\Tayaba Abro\Desktop'); baseFileName=('hand.jpg'); fullFileName=fullfile(folder,baseFileName); format long g; format compact; fontSize = 20;
%IMAGE SEGMENTATION
img=imread(fullFileName);img=rgb2ycbcr(img);for i=1:size(img,1) for j= 1:size(img,2) cb = img(i,j,2); cr = img(i,j,3); if(~(cr > 132 && cr < 173 && cb > 76 && cb < 126)) img(i,j,1)=235; img(i,j,2)=128; img(i,j,3)=128; end endendimg=ycbcr2rgb(img);subplot(2,2,1);image1=imshow(img);axis on;title('Skin Segmentation', 'FontSize', fontSize);set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);%SEGMENTED IMAGE TO GRAYIMAGE
grayImage=rgb2gray(img);subplot(2,2,2);image2=imshow(grayImage);axis on;title('Original Grayscale Image', 'FontSize', fontSize);set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);%GRAY TO BINARY IMAGE
binaryImage = grayImage < 245;subplot(2, 2, 3);axis on;imshow(binaryImage, []);title('Binary Image', 'FontSize', fontSize);% Label the image
labeledImage = bwlabel(binaryImage); % labeling is the process of identifying the connected components in an image and assigning each one a unique label, like this:
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');for k = 1 : length(measurements) thisBB = measurements(k).BoundingBox; rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],... 'EdgeColor','r','LineWidth',2 )end% Let's extract the second biggest blob - that will be the hand.
allAreas = [measurements.Area];[sortedAreas, sortingIndexes] = sort(allAreas, 'descend');handIndex = sortingIndexes(2); % The hand is the second biggest, face is biggest.
% Use ismember() to extact the hand from the labeled image.
handImage = ismember(labeledImage, handIndex);% Now binarize
handImage = handImage > 0;% Display the image.
subplot(2, 2, 4);imshow(handImage, []);title('Hand Image', 'FontSize', fontSize);
Related Question
- Separate two type of object in the image
- How to find the height and width of an object
- How to crop square of size 100 X 100 around the centroid of an image
- Binary Image – Black region detection
- How to detect hand from an image
- I have following code of image extraxtion but i got gray scale image output while giving input color image ,how could i get the color image output
Best Answer