how can i change the value of red in a pixel in a photo?

hi voici le code
clc; clear all; close all;
im=imread('photo.jpg');
b=1;
delta=20;
wi=0
l=impixel(im,1,5);
f=l(1)
m=floor(f/((2^b)*delta));
r=f-(2^b)*m*delta;
f1=(2^b)*m*delta+wi*delta+r/(2^b)
impixel(im,1,5)(1)=f1
le dernier ligne a généré cette erreur
??? Error: File: Untitledtest.m Line: 14 Column: 1
()-indexing must appear last in an index expression.
comment faire pour changer un seul valeur parmi le 3 valeurs dans un pixel choisi??
merci

 채택된 답변

Image Analyst
Image Analyst 2015년 6월 6일
You cannot do this:
impixel(im,1,5)(1)=f1
If you want to set row 1, column 5 of image im to a value of f1, you need to do this:
im(1, 5) = f1;

댓글 수: 7

i know i cant do that, i only wanted to clear my point of vue
look
l=impixel(im,1,5)
give this
l =
232 239 255
i only want to change the 232, not the rest
I(1,5,1) = f1
amira hl
amira hl 2015년 6월 6일
편집: Walter Roberson 2015년 6월 6일
no i actually want to change the value of the red in the pixel itself not in "l"
i want to make changes in the photo
which theoretically means impixel(im,1,5)(1)=10 instead of 232
im(1,5,1) = 10
You cannot assign anything to impixel() because it's a function, so it cannot be on the left hand side of the equals sign. That would be like saying sin(pi) = 42. pi is the input, and 0 is the output - you can't make 42 be the output when it is not .
To assign the red channel of im at row 1, column 5, you have to set the third dimension (1) to 10, just like Walter just showed. If the third dimension is 2 you'd be setting the green, and setting the third dimension to 3 would set the blue value.
clc; clear all; close all;
im=imread('photo.jpg');
l=impixel(im,1,5)
im(1,5,1)=10;
impixel(im,1,5)
executing =>
l =
232 239 255
ans =
232 239 255
nothing change
You need to make sure whether you're dealing with x,y or row, column. Looking at the help to make sure.....
% Read in RGB image.
im = imread('peppers.png');
% Define a row and column.
c = 1;
r = 5;
% Check value of image at row 5, column 1.
rgbValues1 = impixel(im, c, r)
im(r,c,1)=10;
rgbValues2 = impixel(im, c, r)
You get:
rgbValues1 =
63 31 62
rgbValues2 =
10 31 62
Note, impixel takes x,y (which is the same as col, row), whereas indexing an array is always row, col. So you need to make sure you're using the right form (order) in the right place.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2015년 6월 6일

편집:

2015년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by