How can I reconstruct part of an image using imreconstruct

2 visualizaciones (últimos 30 días)
Amani
Amani el 15 de Nov. de 2012
I want to morhpologically reconstruct part of an image based on a line so after identify the position of the line I'm not able to reconstruct the lower part because the size of the marker should be the same as the size of the mask
the code\\\\\\\\\\\
for i=46:65
k= imreconstruct(fe,f1(i:i));
end
//////////////
error\\\\\\\\\\\\
Error using imreconstructmex Function imreconstruct expected MARKER and MASK to be the same size.
Error in imreconstruct (line 77) im = imreconstructmex(marker,mask); \\\\\\\\\\\\\\\\\\\\
I tried to crop both the marker and the mask, it worked but I want to keep the whole image for further analysis
  4 comentarios
Ashish Uthama
Ashish Uthama el 15 de Nov. de 2012
Just looked at your code, I am now not sure if I understand what you are trying to do. Can you post example code using your crop approach and possibly a demo image which comes with the toolbox?
Amani
Amani el 16 de Nov. de 2012
clc;
marker=imread('trees.tif');
mask= ones(size(marker));
mask(6:20,4:50)=0;
rconstructedImage= imreconstruct(marker,mask);

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 16 de Nov. de 2012
Your code doesn't make any sense. You cannot use a single pixel to reconstruct. You have to use a whole binary image the same size as the mask image. Here's a demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'eight.tif';
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
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Image Analysis Demo','numbertitle','off')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
maskImage = imfill(grayImage < 220, 'holes');
% Display the image.
subplot(2, 2, 2);
imshow(maskImage, []);
title('Mask Image (Original Image Thresholded)', 'FontSize', fontSize);
markerImage = false(size(maskImage));
markerImage(20:70, 225:230) = true;
% Display the image.
subplot(2, 2, 3);
imshow(markerImage, []);
title('Marker Image', 'FontSize', fontSize);
finalImage = imreconstruct(markerImage, maskImage);
% Display the image.
subplot(2, 2, 4);
imshow(finalImage, []);
title('Final Reconstructed Image', 'FontSize', fontSize);
  5 comentarios
Image Analyst
Image Analyst el 18 de Nov. de 2012
Well did you try the code I posted for you? Because this is exactly what it does - the same thing as the book. And did you try the code in Steve's book - the example 10.8 you referred to? That works also. If you can't adapt it then post your code and I'll try to fix it when i get time.
Amani
Amani el 19 de Nov. de 2012
yes I tried both of them but I'm still not able to reconstruct half of the coin without cropping ... is there any way to do it? thanks

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by