object recognition using morphological filters
Mostrar comentarios más antiguos
Somehow I have to detect the rectangular components at the bottom right of the image:

The result should look something like this:

I though opening by reconstructing is a good start then I have no clue what to do.
Any help is appreciated
2 comentarios
KALYAN ACHARJYA
el 3 de En. de 2021
More specific please, if you want help, then you need to make it easy to be helped.
Remi MOrre
el 3 de En. de 2021
Respuestas (1)
Image Analyst
el 3 de En. de 2021
Why not just subtract with imabsdiff()?
diffImage = imabsdiff(image1, image2);
bigDifferences = diffImage > 5; % Or whatever.
% Get rid of blobs less than 3 pixels in area
bigDifferences = bwareaopen(bigDifferences, 3); % This is a morphological operation
imshow(bigDifferences, []);
8 comentarios
Remi MOrre
el 3 de En. de 2021
Image Analyst
el 3 de En. de 2021
Actually you didn't attach any images. Just one screenshot of a pair stitched together, and another one that has red arrows annotated on it. If you want anyone to try anything, attach both images as separate attachments either with the image icon or the paper clip icon.
Remi MOrre
el 3 de En. de 2021
Image Analyst
el 3 de En. de 2021
Editada: Image Analyst
el 3 de En. de 2021
So did my code work?
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE 1
folder = pwd;
baseFileName = 'circuit1.png';
grayImage1 = imread(baseFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage1)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage1 = rgb2gray(grayImage1);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage1);
axis('on', 'image');
title('Image 1', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
set(gca,'ColorScale','log')
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE 2
folder = pwd;
baseFileName = 'circuit2.png';
grayImage2 = imread(baseFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage2)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage2 = rgb2gray(grayImage2);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
%--------------------------------------------------------------------------------------------------------
% Display the image with the original, linear colormap.
subplot(2, 2, 2);
imshow(grayImage2);
axis('on', 'image');
title('Image 2', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
% Make sure they are the same size
if ~isequal(size(grayImage1), size(grayImage2))
message = 'Error: images are not the same size';
errordlg(message);
return;
end
%--------------------------------------------------------------------------------------------------------
% SUBTRACT THE IMAGES
diffImage = imabsdiff(grayImage1, grayImage2);
subplot(2, 2, 3);
imshow(diffImage, []);
axis('on', 'image');
title('Differnce Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
bigDifferences = diffImage > 5; % Or whatever.
% Get rid of blobs less than 3 pixels in area
bigDifferences = bwareaopen(bigDifferences, 3); % This is a morphological operation
subplot(2, 2, 4);
imshow(bigDifferences, []);
axis('on', 'image');
title('Big Differences', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
%--------------------------------------------------------------------------------------------------------
% Measure area and locations
props = regionprops(bigDifferences, 'Area', 'Centroid');
allAreas = [props.Area]
xy = vertcat(props.Centroid) % get (x,y) of each centroid.
Remi MOrre
el 4 de En. de 2021
Editada: Remi MOrre
el 4 de En. de 2021
Image Analyst
el 5 de En. de 2021
If you don't have a reference image, how are you going to identify things in the image? There are a bazillion things there in that image. How are you supposed to tell what is different if you don't have a reference image. Different than what? There are many, many rectangular regions in that image. How are we supposed to know which you want? You say you want things in the "bottom right of the image". So do you just want to find rectangular things within a certain distance of the bottom right corner?
Perhaps it's an IR image and you just want to identify things by intensity because they are hotter than the rest? You have to give us some rules for determining how to segment the image.
Remi MOrre
el 5 de En. de 2021
Editada: Remi MOrre
el 5 de En. de 2021
Image Analyst
el 5 de En. de 2021
Yes, like I said, if your definition of an object is something bright, you can find it by thresholding. You can find a full demo in my Image Segmentation Tutorial in my File Exchange.
An erosion does a local minimum operation, so that will make things darker and shrink the bright blobs, possibly making the smaller blobs disappear so that only larger bright blobs remain. Then you thresholded which gave you a binary image of those larger bright blobs. An opening is an erosion followed by a dilation so that makes the binary blobs smaller and then enlarges them again to their original size, roughly. What it does is to smooth out the black parts of the image by getting rid of the small blobs and snipping off any "tendrils" or "peninsulas" that may poke out of the bright blobs. It may potentially separate blobs into more blobs so you may want to call bwareaopen() or bwareafilt() after that. I'm not sure the erosion at the very beginning is really necessary, but whatever -- as long as it works and you're happy with the result.
Categorías
Más información sobre Morphological Operations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!