- Use MATLAB's database toolbox to connect to your database and retrieve the images.
- Convert the image to binary and use edge detection to find boundaries and calculate the perimeter of detected edges.
image processing
1 次查看(过去 30 天)
显示 更早的评论
ive managed to successfully use variables and measure the perimeter of 2 images i have scanned from my flat bed scanner refer : http://www.mathworks.com/matlabcentral/answers/5133-image-processing-calculate-perimeter however now my question is to combine this as a program in which i can scan the images and compare. image uploading has already been completed in .net . now from the database i need to access these images and calculate their perimeters individually . how do i do this. any other questions do let me know. a recap : need to write an individual program to read the scanned images into the code and calculate their perimeters respectilvely thanks
0 个评论
回答(2 个)
Vidhi Agarwal
2024-8-14
Hi Prashan,
I understand your query regarding a program with which you can scan the image, compare them and find the perimeters individually. Below are the steps that can help you in getting started assuming you have access to the images stored in a database and can retrieve them using MATLAB.
Below is the sample code:
% Step 1: Connect to the database and retrieve images
conn = database('your_database_name', 'username', 'password');
sqlquery = 'SELECT image_column FROM your_table';
curs = exec(conn, sqlquery);
curs = fetch(curs);
close(curs);
close(conn);
% Assuming the images are stored as binary blobs, convert them to MATLAB images
images = cell(size(curs.Data, 1), 1);
for i = 1:length(images)
images{i} = imread(curs.Data{i});
end
% Step 2: Calculate the perimeters
perimeters = zeros(length(images), 1);
for i = 1:length(images)
img = images{i};
% Convert to grayscale if necessary
if size(img, 3) == 3
img = rgb2gray(img);
end
% Convert to binary image
bw = imbinarize(img);
% Find edges
edges = edge(bw, 'Canny');
% Calculate perimeter
perimeters(i) = sum(edges(:));
end
% Step 3: Compare perimeters
disp('Perimeters of the images:');
disp(perimeters);
% Example comparison (e.g., difference between first two images)
if length(perimeters) >= 2
perimeter_diff = abs(perimeters(1) - perimeters(2));
fprintf('Difference between the perimeters of the first two images: %f\n', perimeter_diff);
end
For more understanding about database toolbox in MATLAB, refer to the following documentation:
And for edge detection refer to the following documentation:
Hope that helps!
1 个评论
Image Analyst
2024-8-14
There is no need to read all the images into memory. If there are lots of images, that will simply use up all available memory. Better to process them one at a time using dir
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!