This is the image which i am testing.. And code for it is..
I = imread('9.png');
threshold = graythresh(I);
originalImage = im2bw(I, threshold);
i = bwareaopen(originalImage,350);
imshow(i)
m = max(max(i));
[r c] = find(i == m);
fid = fopen('lalit1.txt','wt');
for j=1:length(r)
fprintf(fid,'%f %f\n',r(j),c(j));
end
fclose(fid);
data = textread('lalit1.txt');
r = unique(data);
for i=r',
c = data(data(:,2)==i,1);
z(i,1) = mean([min(c) max(c)]);
end
fid = fopen('lalit2.txt','wt');
for j=1:length(z)
fprintf(fid,'%f %f\n',j,z(j));
end
fclose(fid);
clc;
clear;
fileID = fopen('lalit2.txt');
C = textscan(fileID, '%f32 %f32');
fclose(fileID);
y=cell2mat(C(:,1));
x=cell2mat(C(:,2));
nz = x ~= 0;
y = y(nz);
x = x(nz);
binaryImage = logical(accumarray( ceil([x(:), y(:)]), 1, [480 752]) );
imshow(binaryImage)
Why this program shows error for this attached image.?
Please give me correction..
No products are associated with this question.
What do you think this code does on a binary image (badly named "i"):
m = max(max(i)); [r c] = find(i == m);
Yep, m is one, so it's the same as
[r c] = find(i);
Then you write all pixel locations to a file for some unknown reason. Then you read it all back in with this
data = textread('lalit1.txt');
r = unique(data);
but now r has unique values from all the rows and columns combined, which makes little sense. Then it continues to get crazier from then on. What are you trying to do? Whatever it is, I'm sure this is not the best way of doing it. I don't really understand what the for,c,z loop is supposed to do and why you're messing around with cell arrays, accumarray(), etc. Perhaps it's due to the lack of comments. But anyway, I'm sure there is a much easier way, if I just knew what you were trying to accomplish. Posting an image would help.
I have This original image
.......................
And after running my above code i got this kind of image Whuch i want..
http://speedy.sh/9B5hh/1st.jpg
.........................
The same thing i want to do for this image,
But this code shows this kind of error,
??? Subscripted assignment dimension mismatch.
Nothing matches the equality test, so "c" becomes empty. The min and max of that are empty, the mean of emptiness is empty, and you then try to store that emptiness in a single array location. But a single array location is too big to store emptiness so you get the error.
7 Comments
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115409
What error does it show, on which line?
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115410
When i am running at this,
for i=r',
end
It shows an error,
??? Subscripted assignment dimension mismatch.
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115416
Use the command
and run until the error occurs. When it does, ask
and show them to us.
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115427
I can't understand in program where this has to be added..! So, please give it to me by adding in program..
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115459
At the MATLAB command line, type in the command
Do not put this in your source code, just type it in at the command line.
Then execute your program as normal.
Eventually the program will stop in the debugger at the point you are having the problem. When that happens, at the command line prompt, type in the three commands
Do not put them all on one line; use three separate lines.
Show us the output of those three commands.
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115498
I asked you repeatedly to format code in your questions properly. You did this successfully already, but stop this unfortunately again.
It is not hard, but friendly for the readers.
Direct link to this comment:
http://www.mathworks.com/matlabcentral/answers/55740#comment_115606
size(data)
ans = 19986 2
...............
>> size(c)
ans = 0 1
...............
>> size(i)
ans = 1 1