Manual and Automatic Image Recognition
I need to identify bright and dark spots in an image, but the contrast of these spots is not very good. Processing the image by taking the maximum and minimum contrast values from a portion of the image is always difficult. Someone told me that defining the circularity of contrast could help identify these spots, and this method is feasible. My code is provided below.
My question is: I want to manually designate a region, and then have the program automatically re-identify the bright and dark spots in the designated area after it finishes identifying the rest of the image. For example, in the image below, is there a way to help me identify the black and white circles? Additionally, I want to apply a Voronoi Diagram to the identified spots in the image.
code:
clc
clear
% read image
inpict = imread(‘image.png’);
inpict = im2gray(inpict);
% logfilter image
t=1;
sigma=sqrt(t);
Fsize = ceil(sigma*3)*2+1;
h1 = fspecial(‘gaussian’,[Fsize,Fsize],sigma);
h2 = fspecial(‘log’,[Fsize,Fsize],sigma);
filter1 = uint8(imfilter(inpict,h1,’replicate’));
filter2 = t * imfilter(inpict, h2, ‘replicate’);
bw = filter2 >=0;
filter2= uint8(filter2 + 128);
figure
subplot(221), imshow(filter1);
title(sprintf(‘filtered by Gaussinan, t =%d’,t));
subplot(222), imshow(filter2, []);
title(sprintf(‘filtered by log, t =%d’,t));
subplot(223), imshow(bw*255);
title(sprintf(‘binarized, t =%d’,t));
%Automatic Image Recognition
inpict = imflatfield(filter1,30); %Flat-field correction of images
inpict = adapthisteq(inpict);
inpict = imresize(inpict, 2);
inpict = imadjust(inpict);
%Automatic Image Recognition (1.Creating Local Extreme Masks)
minex = 30; %black
maxex = 20; %white
maskmx = imextendedmax(inpict, minex); % black
maskmn = imextendedmin(inpict, maxex); % white
% 2.Removal of part of the plaque on the border
maskmx = imclearborder(maskmx);
maskmn = imclearborder(maskmn);
% filtering based on patch attributes
minc = 0.2;
maxecc = 0.87;
minarea = 10;
% Maximum Mask
Lmx = bwlabel(maskmx);
Smx = regionprops(maskmx, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smx.Circularity] >= minc …
& [Smx.Eccentricity] <= maxecc …
& [Smx.Area] >= minarea);
maskmx = any(Lmx == permute(goodblobs, [1 3 2]), 3);
% minimum value mask
Lmn = bwlabel(maskmn);
Smn = regionprops(maskmn, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smn.Circularity] >= minc …
& [Smn.Eccentricity] <= maxecc …
& [Smn.Area] >= minarea);
maskmn = any(Lmn == permute(goodblobs, [1 3 2]), 3);
% Visualisation masks and images
outpict = cat(3, im2uint8(maskmx), im2uint8(maskmn), inpict);
imshow(outpict, ‘border’, ‘tight’);I need to identify bright and dark spots in an image, but the contrast of these spots is not very good. Processing the image by taking the maximum and minimum contrast values from a portion of the image is always difficult. Someone told me that defining the circularity of contrast could help identify these spots, and this method is feasible. My code is provided below.
My question is: I want to manually designate a region, and then have the program automatically re-identify the bright and dark spots in the designated area after it finishes identifying the rest of the image. For example, in the image below, is there a way to help me identify the black and white circles? Additionally, I want to apply a Voronoi Diagram to the identified spots in the image.
code:
clc
clear
% read image
inpict = imread(‘image.png’);
inpict = im2gray(inpict);
% logfilter image
t=1;
sigma=sqrt(t);
Fsize = ceil(sigma*3)*2+1;
h1 = fspecial(‘gaussian’,[Fsize,Fsize],sigma);
h2 = fspecial(‘log’,[Fsize,Fsize],sigma);
filter1 = uint8(imfilter(inpict,h1,’replicate’));
filter2 = t * imfilter(inpict, h2, ‘replicate’);
bw = filter2 >=0;
filter2= uint8(filter2 + 128);
figure
subplot(221), imshow(filter1);
title(sprintf(‘filtered by Gaussinan, t =%d’,t));
subplot(222), imshow(filter2, []);
title(sprintf(‘filtered by log, t =%d’,t));
subplot(223), imshow(bw*255);
title(sprintf(‘binarized, t =%d’,t));
%Automatic Image Recognition
inpict = imflatfield(filter1,30); %Flat-field correction of images
inpict = adapthisteq(inpict);
inpict = imresize(inpict, 2);
inpict = imadjust(inpict);
%Automatic Image Recognition (1.Creating Local Extreme Masks)
minex = 30; %black
maxex = 20; %white
maskmx = imextendedmax(inpict, minex); % black
maskmn = imextendedmin(inpict, maxex); % white
% 2.Removal of part of the plaque on the border
maskmx = imclearborder(maskmx);
maskmn = imclearborder(maskmn);
% filtering based on patch attributes
minc = 0.2;
maxecc = 0.87;
minarea = 10;
% Maximum Mask
Lmx = bwlabel(maskmx);
Smx = regionprops(maskmx, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smx.Circularity] >= minc …
& [Smx.Eccentricity] <= maxecc …
& [Smx.Area] >= minarea);
maskmx = any(Lmx == permute(goodblobs, [1 3 2]), 3);
% minimum value mask
Lmn = bwlabel(maskmn);
Smn = regionprops(maskmn, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smn.Circularity] >= minc …
& [Smn.Eccentricity] <= maxecc …
& [Smn.Area] >= minarea);
maskmn = any(Lmn == permute(goodblobs, [1 3 2]), 3);
% Visualisation masks and images
outpict = cat(3, im2uint8(maskmx), im2uint8(maskmn), inpict);
imshow(outpict, ‘border’, ‘tight’); I need to identify bright and dark spots in an image, but the contrast of these spots is not very good. Processing the image by taking the maximum and minimum contrast values from a portion of the image is always difficult. Someone told me that defining the circularity of contrast could help identify these spots, and this method is feasible. My code is provided below.
My question is: I want to manually designate a region, and then have the program automatically re-identify the bright and dark spots in the designated area after it finishes identifying the rest of the image. For example, in the image below, is there a way to help me identify the black and white circles? Additionally, I want to apply a Voronoi Diagram to the identified spots in the image.
code:
clc
clear
% read image
inpict = imread(‘image.png’);
inpict = im2gray(inpict);
% logfilter image
t=1;
sigma=sqrt(t);
Fsize = ceil(sigma*3)*2+1;
h1 = fspecial(‘gaussian’,[Fsize,Fsize],sigma);
h2 = fspecial(‘log’,[Fsize,Fsize],sigma);
filter1 = uint8(imfilter(inpict,h1,’replicate’));
filter2 = t * imfilter(inpict, h2, ‘replicate’);
bw = filter2 >=0;
filter2= uint8(filter2 + 128);
figure
subplot(221), imshow(filter1);
title(sprintf(‘filtered by Gaussinan, t =%d’,t));
subplot(222), imshow(filter2, []);
title(sprintf(‘filtered by log, t =%d’,t));
subplot(223), imshow(bw*255);
title(sprintf(‘binarized, t =%d’,t));
%Automatic Image Recognition
inpict = imflatfield(filter1,30); %Flat-field correction of images
inpict = adapthisteq(inpict);
inpict = imresize(inpict, 2);
inpict = imadjust(inpict);
%Automatic Image Recognition (1.Creating Local Extreme Masks)
minex = 30; %black
maxex = 20; %white
maskmx = imextendedmax(inpict, minex); % black
maskmn = imextendedmin(inpict, maxex); % white
% 2.Removal of part of the plaque on the border
maskmx = imclearborder(maskmx);
maskmn = imclearborder(maskmn);
% filtering based on patch attributes
minc = 0.2;
maxecc = 0.87;
minarea = 10;
% Maximum Mask
Lmx = bwlabel(maskmx);
Smx = regionprops(maskmx, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smx.Circularity] >= minc …
& [Smx.Eccentricity] <= maxecc …
& [Smx.Area] >= minarea);
maskmx = any(Lmx == permute(goodblobs, [1 3 2]), 3);
% minimum value mask
Lmn = bwlabel(maskmn);
Smn = regionprops(maskmn, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smn.Circularity] >= minc …
& [Smn.Eccentricity] <= maxecc …
& [Smn.Area] >= minarea);
maskmn = any(Lmn == permute(goodblobs, [1 3 2]), 3);
% Visualisation masks and images
outpict = cat(3, im2uint8(maskmx), im2uint8(maskmn), inpict);
imshow(outpict, ‘border’, ‘tight’); image analysis, recognition, graphics, image segmentation, skiz MATLAB Answers — New Questions