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