impixelを使用して矩形領域のピクセル値を取得するにはどうすればよいですか。
Afficher commentaires plus anciens
impixel関数を用いて、画像の矩形領域(例えば5行5列の25ピクセル)のピクセル値を取得したいです。
c = [ ];
r = [ ];
impixel (Image , c, r)
において、cとrをどのように定義すればよいでしょうか。
6 commentaires
Atsushi Ueno
le 6 Avr 2023
Déplacé(e) : Atsushi Ueno
le 6 Avr 2023
実直に従えばこうなります。c と r にスカラ値を加算すれば矩形領域の座標を動かす事が出来ます。
Image = imread('peppers.png');
c = [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5] + 130;
r = [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5] + 140;
Pixel = impixel (Image , c, r)
%imshow(uint8(reshape(Pixel,[],5,3)))
Atsushi Ueno
le 6 Avr 2023
Déplacé(e) : Atsushi Ueno
le 6 Avr 2023
もう少し改善すると
Image = imread('peppers.png');
[r,c] = meshgrid(1:5,1:5);
Pixel = impixel(Image,c(:)+130,r(:)+140);
HI
le 6 Avr 2023
Déplacé(e) : Atsushi Ueno
le 6 Avr 2023
HI
le 7 Avr 2023
>meshgridの初期位置は、座標(1, 1)でしょうか。ご教授ください。
⇒はい。オフセット無しなら座標(1, 1)です。実際にプログラムを動かしてみれば一目瞭然です。
[r,c] = meshgrid(1:5,1:5)
[r,c] = meshgrid(11:15,20:22) % 書いた通りに生成されます
HI
le 7 Avr 2023
Réponses (1)
Hiroshi Iwamura
le 6 Avr 2023
余談ですが、対話型ですので
I = imread('peppers.png');
[x, y, p] = impixel(I)
としてマウスクリックで指定すれば(リターンで終了)座標も得られます。
その座標をそのまま使って
p2 = impixel(I,x,y);
とすることもできます。
1 commentaire
HI
le 10 Avr 2023
Catégories
En savoir plus sur 領域とイメージのプロパティ dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!