setting a set of pixel value to zero on an image

9 visualizaciones (últimos 30 días)
Jason Taylor
Jason Taylor el 19 de Nov. de 2018
Respondida: Image Analyst el 20 de Nov. de 2018
So I am having a reall issue trying to remove certain pixel vlaue from this image. So I am using the camera man image and a nosie has been applied to the image as show in code below.
A=imread('cameraman.tif');
x=1:size(A,2); y=1:size(A,1); [X,Y]=meshgrid(x,y);
noise= 30.*cos(2.*pi.*X./15 + 2.*pi.*Y./20);
B=double(A) + noise;
%subplot(1,2,1), imshow(A)
%subplot(1,2,2), imagesc(B); axis
So now if I apply fft2 and fftshift in the code above like so:
A=imread('cameraman.tif');
x=1:size(A,2); y=1:size(A,1); [X,Y]=meshgrid(x,y);
noise= 30.*cos(2.*pi.*X./15 + 2.*pi.*Y./20);
B=double(A) + noise;
%subplot(1,2,1), imshow(A)
%subplot(1,2,2), imagesc(B); axis image; axis image;
D = fft2(B);
C=fftshift(D);
E=imagesc(log((abs(C))))
and the image I get is the one below. I have also added circles to the part that I want to remove.
And this is where I kinda of gte stuck, beacuse I cant seem to figure a away on how to set these pixels to zeros. My attempt so far is this
A=imread('cameraman.tif');
x=1:size(A,2); y=1:size(A,1); [X,Y]=meshgrid(x,y);
noise= 30.*cos(2.*pi.*X./15 + 2.*pi.*Y./20);
B=double(A) + noise;
%subplot(1,2,1), imshow(A)
%subplot(1,2,2), imagesc(B); axis image; axis image;
D = fft2(B);
C=fftshift(D);
E=imagesc(log((abs(C))));
%imcrop(E)
[106.5 105.5 10 20]% Copied co-ordiates for the top red circle
L=(106.5:116.5);
H=(105.5:120.5);
E(L.*H)=0
So in the above code what I have done is, is use imcrop to get the cordinates of the top red circl, from the coordiates I reviced I assumed that it was of the layout
[x,y,x+10, y+10 ]
and put the vlaues of 106.5+10 into my length and 105.5+20 into my width so I then through if I multiply these to together i.e the area of the croped boxed and set them to 0 it would then set remove the highest red circle so when I read E back into the image is dose not seem to work and I am stucked to what I need to do. Is there a possiblty that someone could advise me on where I am going wrong.

Respuestas (2)

Cris LaPierre
Cris LaPierre el 20 de Nov. de 2018
Editada: Cris LaPierre el 20 de Nov. de 2018
I'm not sure I follow your logic, but here's a couple thoughts.
  • Coordinates have to be integers. Try changing from [106.5:116.5] to [106:116]
  • E is an image object and not an image itself. Therefore, E(L.*H)=0 doesn't make sense. Instead, modify C and replot.
L=(106:116);
H=(105:120);
C(L,H)=0;
imagesc(log((abs(C))));

Image Analyst
Image Analyst el 20 de Nov. de 2018
This is exactly what I do in a demo I have posted many times. Just follow along with the attached demo script.
0000 Screenshot.png

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by