coordinate edge of the ceramic into pixel (x,y)
조회 수: 1 (최근 30일)
이전 댓글 표시
i have ceramic images, and how to know coordinate edge of the ceramic into coordinate pixel (x,y) i need coding to find coordinate edge.. pls help
댓글 수: 0
채택된 답변
Image Analyst
2012년 6월 1일
This would be more accurate if you used a black velvet fabric behind your tile. Then you'd simply threshold and call bwboundaries() or bwperim(). You can still try it with a gray background like you have but your edge may not be as sharp and linear. But try this demo code on your image:
clc;
clearvars;
close all;
workspace;
fontSize = 20;
% Read in a tile color demo image.
folder = 'C:\Users\Kurniawan\Documents';
baseFileName = 'tile.jpg';
fullFileName = fullfile(folder, baseFileName);
% 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;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 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);
subplot(2, 2, 2);
imshow(blueChannel, []);
title('Blue Channel Image', 'FontSize', fontSize);
% Threshold blue channel
binaryImage = blueChannel < 163;
% Get rid of small blobs.
binaryImage = bwareaopen(binaryImage, 10000);
% Fill in any holes in the tile.
binaryImage = imfill(binaryImage, 'holes');
% Display it.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Get the boundary coordinates
tileBoundary = bwboundaries(binaryImage);
% Plot boundaries over original image.
subplot(2, 2, 4);
imshow(rgbImage, []);
title('Original Color Image with Boundary', 'FontSize', fontSize);
hold on;
thisBoundary = tileBoundary{1};
xCoordinates = thisBoundary(:, 2);
yCoordinates = thisBoundary(:, 1);
plot(xCoordinates, yCoordinates, 'b-', 'LineWidth', 3);
댓글 수: 2
Elad
2012년 6월 2일
out of curiosity, how did you choose the blue plane and the value 163 for the treshold ?
Image Analyst
2012년 6월 2일
I knew it would be the blue plane because the tile was reddish. So the red signal would be high, like the white background, while the red signal would be low, much darker than the white background. Thus the blue channel would give the most contrast. I used my thresholding app in the File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 to determine the threshold. Of course you could also have done that with Photoshop, or just display the histogram of the blue channel in MATLAB and look at it to see the two histogram humps and what gray level you need to use to split them apart.
추가 답변 (1개)
Elad
2012년 6월 1일
try this .. a=imread() ; a=rgb2ycbcr(a); a=a(:,:,2); a=edge(a,'canny',[0.1 0.5],15); you can get the coordinates using find() for ones.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!