How to use blockproc by location?

조회 수: 2 (최근 30일)
Elder Winter
Elder Winter 2019년 6월 16일
댓글: Image Analyst 2019년 6월 20일
Hy all, is blockproc could be used to block by location(x,y) that i give? Ex: I have image with 64x64 pixels, and i want to turn white every pixel around location point(x,y), let's say i want to change [3 3] around the point. could blockproc do it? or there any suggestion for me?
Thanks, :).

채택된 답변

Image Analyst
Image Analyst 2019년 6월 16일
편집: Image Analyst 2019년 6월 16일
Yes, you can even do that without blockproc(). Here's how
yourImage = uint8(255 * ones(yourImage));
that will turn every pixel, at every (x,y) location, white (assuming a uint8 image).
Also, see attached demos for blockproc().
  댓글 수: 5
Steven Lord
Steven Lord 2019년 6월 20일
There's no need to set each element individually. Address a matrix of elements on the left side of the equals sign and specify a matrix of the same size on the right.
>> A = zeros(5);
>> cent = [2, 3];
>> A(cent(1)+(-1:1), cent(2)+(-1:1)) = magic(3)
This replaces the submatrix in the first through third rows (2 + (-1:1)) and the second through fourth column (3 + (-1:1)) of A (which is a 3-by-3 submatrix of A) with the 3-by-3 magic matrix. If you don't like the negative numbers in that expression, specify the upper-left corner of the submatrix to be replaced / filled rather than the center.
>> B = zeros(5);
>> ulc = [1 2];
>> B(ulc(1)+(0:2), ulc(2)+(0:2)) = magic(3)
Image Analyst
Image Analyst 2019년 6월 20일
Elder, I don't recall you saying anything about T, the gradient color, or locs variable before your last comment above. Where did you get locs from? Why not just do a for loop over all rows in locs?
for k = 1 : size(locs, 1)
% Replace this 3x3 block with the values from T{k}:
grayImage(locs(k,1)-1:locs(k,1)+1, locs(k,2)-1:locs(k,2)+1) = T{k};
end
Make sure locs is a list (row, column) coordinates, and not (x,y), or else you won't replace the correct locations!

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

추가 답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 16일
편집: KALYAN ACHARJYA 2019년 6월 16일
#Edited
Considering Input Image is Gray, let say image1 and location of pixel is x,y
image1(y-1:y+1,x-1:x+1)=255;
  댓글 수: 5
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 16일
Thank you @Walter @ImageAnalyst
Elder Winter
Elder Winter 2019년 6월 20일
Ohhh, it like block whole area around the point, and turn it to white. Thank You.

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


Walter Roberson
Walter Roberson 2019년 6월 16일
편집: Walter Roberson 2019년 6월 16일
blockproc is a waste for this kind of task, but it can be done. You would specify a blocksize of 3 x 3 and an overlap of [1 1], and then in the block_struct that is passed to your function, you would test for location == [y-1, x-1] and make the change in that case and otherwise return the input.
But there is just no point to this as you can go directly to that block.
YourImage(y-1:y+1, x-1:x+1, :) = 255; %assuming uint8
If you do not want to touch the center pixel then
YourImage(y-1:y+1, [x-1 x+1], :) = 255;
YourImage([y-1 y+1], x, :) = 255;
  댓글 수: 1
Elder Winter
Elder Winter 2019년 6월 20일
Hmmm, this looks same as above. but i want to change the center too, of course. Thank You

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by