Why is my prompt inpudlg isn´t functional?

Dear all,
I would like to use prompt (inputdlg) for setting my points in segmentation like this:
fontSize = 15;
% baseFileName = '110.jpg';
baseFileName = 'thorax-mdl.jpg';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Načtení obrazu.
grayImage = imread(fullFileName);
grayImage_pater = imread (fullFileName);
% Dimenze obrazu.
% numberOfColorBands by měl být = 1.
% ***
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);%
%Práh pro vytvoření binárního obrazu okolí
thresholdValue = 180;
binaryImage_okoli = eq_grayImage > thresholdValue;
% Odstranění okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vyplnění otvorů.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvorů.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 750);
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
figure(5);
imshow(grayImage);
hold on
prompt = {'Nastavení počtu komponentů:'};
dlg_title = 'Nastavení parametrů segmentace';
defaultans = {'50'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
% a = str2double( x{1,1} );
a = str2double(answer);
Npts1 = 35; % počet bodů interpolovaných hranic
% Npts2 = 25; % počet bodů interpolovaných hranic
% Npts3 = 5; % počet bodů interpolovaných hranic
Ncomps = a; % počet komponentů
shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
tmp=shape.thorax{1};
plot(tmp(:,2), tmp(:,1), 'o-b')
legend('Okolí hrudníku')
And I attach my function Model and original image thorax-mdl.jpg.
But I have this error:
Error using bwboundaries
Expected input number 1, BW, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was cell.
Error in bwboundaries>parseInputs (line 173)
validateattributes(BW_in, {'numeric','logical'}, {'real','2d','nonsparse'}, ...
Error in bwboundaries (line 135)
[BW, conn, findHoles] = parseInputs(varargin{:});
Error in Model (line 7)
Components{i} = bwboundaries(bwboundaries(tmp{i}, Ncomps), linspace(0, 1,
Npts1));
Error in opraveni (line 62)
shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
Thank you for your answers.

4 Comments

I tried your code and the "fourier_fit" function is missing for me.
Anyways - in line 2 of your model.m it says
tmp = bwboundaries(Img);
After that your tmp variable is a cell array for the boundaries. It seems there is a problem with the variable class. Also - your attached Model.m does not have the line 7 as specified in your error report. I would use debugging to go through the code line by line to see what exactly gives you the error. Just check that bwboundaries is not called with a cell as input but a single matrix.
Ou, I forgot to add bwboundaries. Because I use bwboundaries instead of fourier_fit function. So this is my code:
fontSize = 15;
% baseFileName = '110.jpg';
baseFileName = 'thorax-mdl.jpg';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Načtení obrazu.
grayImage = imread(fullFileName);
grayImage_pater = imread (fullFileName);
% Dimenze obrazu.
% numberOfColorBands by měl být = 1.
% ***
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);%
%Práh pro vytvoření binárního obrazu okolí
thresholdValue = 180;
binaryImage_okoli = eq_grayImage > thresholdValue;
% Odstranění okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vyplnění otvorů.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvorů.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 750);
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
figure(4)
imshow(grayImage, []);
title('Segmentace okolí', 'FontSize', fontSize);
axis image;% Ujištění, že se obraz po zvětšení okna nezdeformuje.
hold on;
% Nastavení obrazu.
% Zvětšení obrazu na celou obrazovku.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Odstranění panelu nástrojů a rozbalovacího menu.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Přidání titulku okna.
set(gcf, 'Name', 'Segmentace okolí', 'NumberTitle', 'Off')
tmp = bwboundaries(binaryImage_okoli);
shape.thorax = tmp{1};
% boundaries = bwboundaries(handles.binaryImage_okoli);
numberOfBoundaries = size(tmp, 1);
for k = 1 : numberOfBoundaries
thisBoundary = tmp{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 2);
end
figure(5);
imshow(grayImage);
hold on
prompt = {'Nastavení počtu komponentů:'};
dlg_title = 'Nastavení parametrů segmentace';
defaultans = {'50'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
% a = str2double( x{1,1} );
a = str2double(answer);
Npts1 = 35; % počet bodů interpolovaných hranic
% Npts2 = 25; % počet bodů interpolovaných hranic
% Npts3 = 5; % počet bodů interpolovaných hranic
Ncomps = a; % počet komponentů
shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
tmp=shape.thorax{1};
plot(tmp(:,2), tmp(:,1), 'o-b')
legend('Okolí hrudníku')
In Model.m I didn´t change anything. Now, I have this error:
Error using coder.internal.errorIf (line 8)
A scalar connectivity specifier CONN must either be 4 or 8.
Error in bwboundaries>parseInputs (line 197)
coder.internal.errorIf(conn~=4 && conn~=8, ...
Error in bwboundaries (line 135)
[BW, conn, findHoles] = parseInputs(varargin{:});
Error in Model (line 7)
Components{i} = bwboundaries(bwboundaries(tmp{i}, Ncomps), linspace(0, 1,
Npts1));
Error in opraveni (line 84)
shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
Is this the final output?
Yes! Please, how did you do that?

Sign in to comment.

 Accepted Answer

There is no problem with inputdlg. Instead of calling function model.m, use:
% shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
shape.thorax=bwboundaries(binaryImage_okoli);
If you use this, there is no purpose of inputdlg.

14 Comments

Okay, thank you. But if I need to set up the number of this points(bwboundaries)? For example reduce their number. So I need to use inpudlg. Don´t you know how to do it?
Yo mean, now tmp is of size 1296*2. You want to reduce it to the size given by inputdlg ?
I want to change number of Ncomps and Npts1. To make it look like this:
Yes, I want to reduce size of tmp 1296*2, for better next processing. Is it possible? Or is it impossible?
It is very much possible. I will get back once I get into office.
Okay, thank you so much.
I would still ask you a question about prompt. If I have this code :
prompt = {'Nastavení výšky modelu:','Nastavení jemnosti sítě modelu:','Nastavení počtu elektrod:','Nastavení vzdálenosti mezi elektrodami:','Nastavení poloměru elektrod:','Nastavení tvaru elektrod:','Nastavení jemnosti sítě elektrod:','Nastavení kontur:'};
dlg_title = 'Nastavení parametrů modelu';
defaultans = {'1','0.8','16','1','0.05','0','0.4','256'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
params.Height = 1;
params.Norm = 256;
params.Refi = 0.8;
params.NumEl = 16;
params.DistEl = 1;
params.RadEl = 0.05;
params.ShapeEl = 0;
params.RefiEl = 0.4;
params.Norm = 256;
but this prompt doesn´t work, parameters after overwriting is not saved in the workspace. Please, advice me? Thank you
First of all, you're not doing anything with the user's response - what you called "answers". Then you're assigning some constants to params (basically ignoring the user's inputs). Whether it gets "saved" in the workspace depends on what workspace you're talking about. Those constants should/will be saved in the local workspace of whatever function or script you're running.
If you want to use the user's responses, then you need to use answers:
params.Height = answers{1};
params.Norm = answers{2};
and so on.
Okay, it´s help. Thank you very much. But I have to convert this char number to double number for further use. How to make convert? Because char2double isn´t right.
clc; clear all;
fontSize = 15;
% baseFileName = '110.jpg';
baseFileName = 'thorax-mdl.jpg';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Na?tení obrazu.
grayImage = imread(fullFileName);
grayImage_pater = imread (fullFileName);
% Dimenze obrazu.
% numberOfColorBands by m?l být = 1.
% ***
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho p?evést na ?ernobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho p?evést na ?ernobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);%
%Práh pro vytvo?ení binárního obrazu okolí
thresholdValue = 180;
binaryImage_okoli = eq_grayImage > thresholdValue;
% Odstran?ní okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vypln?ní otvor?.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvor?.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 750);
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
figure(4)
imshow(grayImage, []);
title('Segmentace okolí', 'FontSize', fontSize);
axis image;% Ujišt?ní, že se obraz po zv?tšení okna nezdeformuje.
hold on;
% Nastavení obrazu.
% Zv?tšení obrazu na celou obrazovku.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Odstran?ní panelu nástroj? a rozbalovacího menu.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% P?idání titulku okna.
set(gcf, 'Name', 'Segmentace okolí', 'NumberTitle', 'Off')
tmp = bwboundaries(binaryImage_okoli);
shape.thorax = tmp{1};
% boundaries = bwboundaries(handles.binaryImage_okoli);
numberOfBoundaries = size(tmp, 1);
for k = 1 : numberOfBoundaries
thisBoundary = tmp{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 2);
end
figure(5);
imshow(grayImage);
hold on
prompt = {'Nastavení po?tu komponent?:'};
dlg_title = 'Nastavení parametr? segmentace';
defaultans = {'50'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
% a = str2double( x{1,1} );
a = str2double(answer);
Npts1 = 35; % po?et bod? interpolovaných hranic
% Npts2 = 25; % po?et bod? interpolovaných hranic
% Npts3 = 5; % po?et bod? interpolovaných hranic
Ncomps = a; % po?et komponent?
% shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
shape.thorax=bwboundaries(binaryImage_okoli);
tmp=shape.thorax{1};
%%do interpolation
x = tmp(:,2) ; y = tmp(:,1) ;
% select according to Ncomps
skip = ceil(length(x)/Ncomps) ;
xi = x(1:skip:end) ;
yi = y(1:skip:end) ;
plot(xi,yi, 'o-b')
legend('Okolí hrudníku')
@Veronika: the unfortunately named str2double does the job though.
KSSV: Thank you very much.
But, I have still one problem this blue curve isn´t closed. I mean this:
Is there any option for connect these points? Thank you for your answer.
Stephen Cobeldick: I tried str2double, but this error appears:
Cell contents reference from a non-cell array object.
Error in DP_segment_final>Okoli_Callback (line 420)
params.Height = answer{1};
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in DP_segment_final (line 44)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)DP_segment_final('Okoli_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Can you advice me?

Sign in to comment.

More Answers (0)

Asked:

on 13 Apr 2017

Commented:

on 17 Apr 2017

Community Treasure Hunt

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

Start Hunting!