Hello, I want to detect the shape from the attached image.Please help me to detect the shape from the image.Here is the image link(imgur.com/cpNL9oH)and i want to detect the irregular shape from this image and from this another image(imgur.com/JvRCD0g)i want to detect the circle shape.Like this(<http://imgur.com/tUtUvNM).This> is a mammogram photo. I did some segmentation operation.
MATLAB: Object shape detection from the image.
Image Processing Toolboxmammogramradiograph
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 wouldn't do it that inefficient way at all. But that's another issue. Your problem is that you're casting your color image to a logical image, e, and then displaying that e instead of the color image c. Why are you doing that? Also, I apply a colormap after I've displayed the image, not before and I'm not sure if displaying an image will reinitialize the colormap.
I'd do it like this:
rgbImage=imread('new2.png');% Display the original color image.
subplot(2, 3, 1);imshow(rgbImage);title('Original Color Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);greenChannel = rgbImage(:, :, 2);blueChannel = rgbImage(:, :, 3);binaryImageR = redChannel > 233;binaryImageG = redChannel > 25 & redChannel < 30;binaryImageB = blueChannel > 35 & blueChannel < 40;% Display the binary images.
subplot(2, 3, 2);imshow(binaryImageR);title('Red Binary Image', 'FontSize', fontSize);subplot(2, 3, 3);imshow(binaryImageG);title('Green Binary Image', 'FontSize', fontSize);subplot(2, 3, 4);imshow(binaryImageB);title('Red Binary Image', 'FontSize', fontSize);% Combine
binaryImage = binaryImageR & binaryImageG & binaryImageB;subplot(2, 3, 5);imshow(binaryImage);title('Overall Binary Image', 'FontSize', fontSize);% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(binaryImage,class(rgbImage)));subplot(2, 3, 6);imshow(maskedRgbImage);title('Masked Color Image', 'FontSize', fontSize);
Best Answer