How to Invert Pixels in a Specific Window of an Image Using MATLAB?

In summary, inverting pixels in Matlab images is a technique used to enhance contrast and brightness, convert negative images to positive ones, and can be done using the "imcomplement" function. It does not significantly affect image quality, but can make certain features more visible. The inversion can be undone by applying the function again. Other methods for enhancing images in Matlab include adjusting brightness and contrast, applying filters, and using other image processing techniques.
  • #1
Jordon
1
0

Homework Statement



1.invert all pixel of a 20x20 window around I(X,Y)
2.set all pixel aroud the in the inverted images

Homework Equations


cant make work right way.
Please help me to solve problem.
Thanks,


The Attempt at a Solution


I=imread('test7.jpg'); % Load the image file and store it as the variable I.
x1=floor(rand*240+8);% generate random varible x1
y1=floor(rand*240+8);% generate random varible y1
for i=y1-7:y1+7
for j=x1-7:x1+7 % Show15x15 With (x,y) in the center
Ired(i,j)=I(i,j);
end
end
B=inv(Ired);
imshow(B); % show the modified image
 
Physics news on Phys.org
  • #2


Hi there,

To invert all the pixels in the 20x20 window around I(X,Y), you can use the following code:

I = imread('test7.jpg'); % Load the image file and store it as the variable I.
x1 = floor(rand*240+8); % generate random variable x1
y1 = floor(rand*240+8); % generate random variable y1
for i = y1-7:y1+7
for j = x1-7:x1+7 % Show 15x15 with (x,y) in the center
I(i,j) = 255 - I(i,j); % invert the pixel value by subtracting it from 255 (assuming the image is grayscale)
end
end
imshow(I); % show the modified image

To set all the pixels around the inverted image, you can use the following code:

B = inv(I); % invert the entire image
for i = 1:size(B,1) % loop through the rows of the image
for j = 1:size(B,2) % loop through the columns of the image
if i >= y1-6 && i <= y1+6 && j >= x1-6 && j <= x1+6 % if the current pixel is within the 13x13 window around (x,y), set it to the corresponding pixel in the inverted image
I(i,j) = B(i,j);
end
end
end
imshow(I); % show the modified image

Hope this helps! Let me know if you have any further questions.
 
  • #3


Hello,

It looks like you are attempting to invert the pixels of a 20x20 window around a specific point (x,y) in an image. Your code appears to be generating a random point (x1,y1) and then selecting a 15x15 window centered around that point. However, you are not actually inverting the pixels in this window. Instead, you are simply copying the original image into a new variable (Ired).

To invert the pixels, you will need to loop through each pixel in the window and calculate its inverse. This can be done using the 'inv' function in Matlab. Additionally, you will need to set the pixels around the inverted window to the inverted values. This can be done by using the same loop structure and setting the appropriate pixels to the inverted values.

I would suggest breaking down the problem into smaller steps and testing each step individually to make sure it is working correctly. Also, make sure to check the dimensions of your variables and make sure they match the desired window size. Good luck!
 

Related to How to Invert Pixels in a Specific Window of an Image Using MATLAB?

1. What is the purpose of inverting pixels in Matlab images?

Inverting pixels in Matlab images is a common technique used to enhance the contrast and brightness of an image. It can also be used to convert a negative image to a positive image, or vice versa.

2. Can I invert specific pixels in an image using Matlab?

Yes, you can invert specific pixels in an image using Matlab by accessing the individual pixel values and changing them to their inverted values. This can be done using the "imcomplement" function.

3. How does inverting pixels affect the quality of an image?

Inverting pixels does not necessarily affect the overall quality of an image. However, it can make certain features more visible and enhance the contrast and brightness of the image.

4. Can I undo the inversion of pixels in an image?

Yes, you can undo the inversion of pixels in an image by simply applying the "imcomplement" function again to the inverted image. This will revert the pixels back to their original values.

5. Are there any other methods for enhancing an image in Matlab?

Yes, there are various other methods for enhancing an image in Matlab, such as adjusting brightness and contrast, applying filters, and using other image processing techniques. Inverting pixels is just one of many options available.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
173
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
7K
  • Electrical Engineering
2
Replies
43
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
30K
Back
Top