why the output image lines are doubled?
Show older comments
Dear all
I have the following image1 as an input for my code,

The code is:
load('matlab')
mdl = 'TwoVoltsTanhtestmodel2';
rgbImage = imread('/home/salibensuleiman/Documents/MATLAB/Escher/Escher/image1.png');
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels > 1
grayImage = rgbImage(:, :, 1); % Take red channel.
else
grayImage = rgbImage; % It's already gray scale.
end
binaryImage = grayImage < 128;
subplot(2, 2, 2);
imshow(binaryImage, []);
.
.
.
The rest of the code is a parallel processing for this image which I did not include it here for simplicity.
The output image is attached.

I noticed the lines are doubled although my code is just checking the pixels one by one if the neighbours are for example 1 they keep it one otherwise change it to zero.
4 Comments
Image Analyst
on 21 Nov 2018
You forgot to show us the part of the code that doubles it. What you have here just shows the input image and it looks as expected.
Stephen23
on 22 Nov 2018
sali's "Answer" moved here and formatted correctly:
The 2nd image is the output image after removing the horizontal lines, the diagonal lines should remaine as they are but as you noticed they are doubled.
this is the whole code:
load('matlab')
mdl = 'TwoVoltsTanhtestmodel2';
load('matlab')
mdl = 'TwoVoltsTanhtestmodel2';
rgbImage = imread('/home/salibensuleiman/Documents/MATLAB/Escher/Escher/image1.png');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale imag
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it'
% Use weighted sum of ALL channels to create a gray
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by tak
% which in a typical snapshot will be the least noi
grayImage = rgbImage(:, :, 1); % Take red channel.
else
grayImage = rgbImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
% Binarize the image
binaryImage = grayImage < 128;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
%Parallel processing part
U=zeros(102,102);
Y=zeros(102,102);
for i=2:101
for j=2:101
U(i,j)=binaryImage(i-1,j-1);
end
end
PartialArray=zeros(3,3,10000);
PartialY=zeros(3,3,10000);
d=0;
k=1;
page=0;
for i =1:100
for j=1:100
page=page+1;
for row=i:i+2
d=d+1;
for col=j:j+2
PartialArray(d,k,page)=U(row,col);
PartialY(d,k,page)=Y(row,col);
k=k+1;
end
k=1;
end
d=0;
end
end
numParamSets = 10000;
% Create parameter sets:
assignin('base',['Y11ini' ],0);
assignin('base',['Y12ini' ],0);
assignin('base',['Y13ini' ],0);
assignin('base',['Y21ini' ],0);
assignin('base',['Y22ini' ],0);
assignin('base',['Y23ini' ],0);
assignin('base',['Y31ini' ],0);
assignin('base',['Y32ini' ],0);
assignin('base',['Y33ini' ],0);
paramSets = cell(1, numParamSets);
idx = 1;
M = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
for page = 1:10000
paramSets{idx} = Simulink.BlockDiagram.modifyTunableParameters(...
M,...
'U11',PartialArray(1,1,page),...
'U12',PartialArray(1,2,page),...
'U13',PartialArray(1,3,page),...
'U21',PartialArray(2,1,page),...
'U22',PartialArray(2,2,page),...
'U23',PartialArray(2,3,page),...
'U31',PartialArray(3,1,page),...
'U32',PartialArray(3,2,page),...
'U33',PartialArray(3,3,page),...
'Y11ini',PartialY(1,1,page),...
'Y12ini',PartialY(1,2,page),...
'Y13ini',PartialY(1,3,page),...
'Y21ini',PartialY(2,1,page),...
'Y22ini',PartialY(2,2,page),...
'Y23ini',PartialY(2,3,page),...
'Y31ini',PartialY(3,1,page),...
'Y32ini',PartialY(3,2,page),...
'Y33ini',PartialY(3,3,page));
idx = idx+1;
end
numSimCmdArgStructs = numParamSets;
simCmdParamValStructs = cell(1, numSimCmdArgStructs);
paramValStruct.SaveTime = 'on';
paramValStruct.SaveOutput = 'on';
paramValStruct.SimulationMode = 'rapid';
paramValStruct.RapidAcceleratorUpToDateCheck = 'off';
paramValStruct.RapidAcceleratorParameterSets = [];
paramValStruct.LimitDataPoints = 'off';
idx = 1;
for paramSetsIdx = 1:numParamSets
simCmdParamValStructs{idx} = paramValStruct;
simCmdParamValStructs{idx}.RapidAcceleratorParameterSets = paramSets{paramSetsIdx};
idx = idx + 1;
end
Yout=zeros(10000,1,10000);
out = cell(1, numSimCmdArgStructs);
l=1;
%for l=1:2
parfor(i = 1:numSimCmdArgStructs)
out{i} = sim(mdl, simCmdParamValStructs{i});
end
for i=1:numSimCmdArgStructs
t = out{i}.find('tout');
y = out{i}.find('Y22');
PartialY(2,2,i)=y(end);
Yout(i,1,l)=y(end);
end
g=1;
figure(g)
z=((reshape(Yout(:,:,g),[100,100])));
z1=imshow(z);
hold on;
Image Analyst
on 22 Nov 2018
I did NOT notice that there were doubled. Like I said, all I see is the input image.
I can't even run your code now without the MATLAB.MAT file. Please attach it.
sali
on 22 Nov 2018
Answers (0)
Categories
Find more on Get Started with Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!