How to generate a bitmap image without using function...Please help

How can i generate bitmap representation of an image using thresholding?? below code didn't work....
for i=1:r
for j=1:s
thresh=C(i,j)+Di;
if(imean(i,j)>=thresh)
bm(i,j)=1;
else
bm(i,j)=0;
end
end
end
figure
imshow(bm);

8 comentarios

Sreeda M A
Sreeda M A el 29 de Jun. de 2016
Editada: Geoff Hayes el 29 de Jun. de 2016
I am getting an error like this :
Attempted to access C(2,1); index out of bounds because size(C)=[1,256].
Error in content (line 51)
thresh=C(i,j)+Di;
Sreeda - how are r and s initialized? You are trying to iterate over C which is a 1x256 matrix yet r is at least two. Please clarify where these values have come from and how they relate to C.
r and s are size of image....256*256 respectively
@Sreeda M A: Don't waste your time writing loops. MATLAB is a high-level language, so you don't need to mess around with ugly loops. See Walter Roberson's answer for the simplest and fastest solution.
If r and s are the size of your image, then your image is stored in some variable other than C.
I changed the code as shown below
imean=padarray(imean,[3,3],0);
for i=1:256
for j=1:256
m1=imean(i:i+2,j:j+2);
thresh=n1(i,j)+sod;
if(m1(i,j)>=thresh)
bm(i,j)=1;
else
bm(i,j)=0;
end
end
end
Here imean is an interband average image,n1 is the minimum of that image and sod is scaled version of dither array......
Image Analyst
Image Analyst el 4 de Jul. de 2016
Editada: Image Analyst el 4 de Jul. de 2016
I fixed your formatting for you, but please read this.
Also to do a locally adaptive threshold like you did, you can do it vectorized if you just create an m1 (or n1) image with conv2() or imfilter(), then use >=. Let me know if you can't figure it out.
bm =
Sorry sir ,but I can't figure it out .

Iniciar sesión para comentar.

Respuestas (1)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Jun. de 2016

Comentada:

el 10 de Ag. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by