From: Digistar You on
Dear all,

I want to find the number of neighboring regions and shared border pixels of a region in an image with labeled regions. For example, an labeled image L with 45 regions (region labels from 1 - 45). I used the following commands:
[glcm, SI] = graycomatrix(L, 'NumLevels', 45, 'GrayLimits', [],'offset',[0 1; 0 -1; 1 0; -1 0]); % Only 4-connected pixels required.
glcm = sum(glcm, 3);

However, the result glcm is not correct, and I think the reason is that SI is not identical to L, glcm was derived from SI, not L. Because I have written another function, which is absolutely correct but is very slow. If I input SI to that function, it gave the same result as glcm. So, could you please tell me how I can use this function with what parameters, such that I can get SI which is identical to L? and get the correct result?

Thank you very much.
From: ImageAnalyst on
Post your image to http://drop.io
From: Digistar You on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <de8e35ec-f33e-4e76-8277-56cb3b6c7b9d(a)i37g2000yqn.googlegroups.com>...
> Post your image to http://drop.io
Thanks. But did I not clearly describe my question?
From: Image Analyst on
No, you didn't. I like to have images when I do image processing - maybe I'm unusual in that way but that's my preference. And you're not making it easy. I spent several minutes trying to create a sample image with voronoi(), but it got too complicated so I gave up. I'm puzzled why you're so reluctant to enable people to easily help you. But whatever, good luck. You can always call the Mathworks with your questions. Maybe instead you want to just compare distances between centroids but that won't be as good or accurate a method as thickening your labeled image and using graycomatrix.
From: Image Analyst on
OK for some reason I took an interest in it, and went to some trouble for you to create a demo image myself (from the standard coin demo image). See if this demo makes sense to you:
Make sure you join any lines split into two by the newsreader!

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear all; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 18;

% Read in standard MATLAB grayscale demo image.
grayImage = imread('eight.tif');
subplot(3, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

binaryImage = imfill(grayImage < 200, 'holes');
binaryImage = bwareaopen(binaryImage, 1000);
subplot(3, 3, 2);
imshow(binaryImage, []);
title('Binary Image');

adjacentImage = bwmorph(binaryImage, 'thick', inf);
subplot(3, 3, 3);
imshow(adjacentImage, []);
title('Adjacent Image');

[labeledImage numberOfBlobs] = bwlabel(adjacentImage, 8); % Label each blob so we can make measurements of it
subplot(3, 3, 4);
imshow(labeledImage, []);
title('Labeled Image');

% Label the blobs.
blobMeasurements = regionprops(labeledImage, 'centroid');
for k = 1 : numberOfBlobs % Loop through all blobs.
blobCentroid = blobMeasurements(k).Centroid; % Get centroid.
text(blobCentroid(1), blobCentroid(2), num2str(k), ...
'Color', [0 0 1], 'FontSize', fontSize);
end

coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
subplot(3, 3, 5);
imshow(coloredLabels, []);
title('Colored Labeled Image');

adjacentImageL = imdilate(labeledImage, ones(3));
subplot(3, 3, 6);
imshow(adjacentImageL, []);
title('Adjacent Labeled Image');

% Finally, we now have the image that we can use graycomatrix on.
kernel = [0 1; 0 -1; 1 0; -1 0];
glcm = graycomatrix(adjacentImageL, 'NumLevels', numberOfBlobs, 'GrayLimits', [],'offset',kernel);
for k = 1:size(glcm,3);
glcm(:,:,k) % Display in the command window.
end

% Combine all directions into one.
glcm = sum(glcm, 3);
subplot(3, 3, 7);
imshow(glcm, []);
title('GLCM');

% Go through saying which blob is next to which other blob.
for row = 1:numberOfBlobs
for col = row+1:numberOfBlobs
if glcm(row, col) > 0
promptMessage = sprintf('Blobs #%d and #%d are next to each other.', row, col);
else
promptMessage = sprintf('Blobs #%d and #%d are NOT next to each other.', row, col);
end
button = questdlg(promptMessage, 'Continue', 'Continue', 'Cancel', 'Continue');
if strcmp(button, 'Cancel')
return;
end
end
end
 |  Next  |  Last
Pages: 1 2
Prev: jumping to output directly
Next: need help on imread