Processing 구현중 2
Photoshop Memo
포토샵의 이미지 크기 표현 방법
Image > Image Size
1. Pixel Dimensions 픽셀 단위의 해상도 정보
2. Document Size 외부 프로그램에서 불러왔을 때의 크기 (cm or 인치)
여러 장의 이미지 크기 일괄 조정
File > Scripts > Image Processor
폴더 선택 후 Resize
여러 장의 이미지 일괄 작업 - Action 기능 이용
Action 기능이란 쉽게 말해서 한 장의 이미지에 수행하는 작업을 촬영하여 기록해 두는 방법이다.
차후 이것을 다른 이미지에 대하여 재생하면 된다.
Window > Action 선택하여 액션 창 활성화
Create New Set 버튼 선택 후 새 액션 이름 입력
Create New Action 버튼 선택
재생 버튼 선택 후 작업
출처 http://azdesigntm.com/680
흑백사진의 일부를 RGB로 남겨두는 방법
Image > Adjustments > Desaturate (RGB 이미지를 흑백으로 전환)
새 레이어 생성
도구 중 History Brush를 선택하여 RGB로 재전환할 부분을 터치
keyPressed()
void draw()
{
if (keyPressed == true) // 어떠한 키가 눌려진 상태이면
{
fill(0); // 검정색 붓
}
else // 아니면
{
fill(255); // 흰색 붓
}
rect(25, 25, 50, 50); // 그러고 사각형 그리렴
}
Pixels[]
Array containing the values for all the pixels in the display window. These values are of the color datatype.
디스플레이 창의 픽셀 색깔 정보를 담고 있는 배열.
This array is the size of the display window. 자동적으로 이 배열의 크기는 디스플레이 창의 크기(총 픽셀 개수)와 같다. For example, if the image is 100x100 pixels, there will be 10000 values and if the window is 200x300 pixels, there will be 60000 values.
The index value defines the position of a value within the array.
첫번째 줄 왼쪽 끝부터 카운트. 줄이 바뀌어도 카운트는 계속됨.
For example, the statement color b = pixels[230]will set the variable b to be equal to the value at that location in the array. 예를 들어 폭 200인 디스플레이 창인 경우 pixels[230] 안에는 둘째 줄 31번째 픽셀의 값이 담김.
Before accessing this array, the data must loaded with the loadPixels() function.
pixels[] 배열에 접근하기 전에는 반드시 loadPixels() 함수를 실행시켜야 함.
After the array data has been modified, the updatePixels() function must be run to update the changes.
이미지 정보가 바뀜에 따라 pixels[] 배열 값을 변경하고 싶으면 updatePixels() 함수로 업데이트를 해 줘야 함.
Without loadPixels(), running the code may (or will in future releases) result in a NullPointerException.
loadPixels() 실행시키지 않으면 널포인터익셉션 에러 발생.
다음은 예제
출처 http://www.learningprocessing.com/examples/chapter-15/example-15-7/
PImage img;
void setup()
{
size(200, 200);
//size(580,386); // 원 이미지의 Pixel Dimension 값과 동일한 크기의 디스플레이 창
img = loadImage("city.jpg");
}
void draw()
{
loadPixels(); // 픽셀정보 로드.
// We must also call loadPixels() on the PImage since we are going to read its pixels.
// img를 주체로 하여 픽셀정보 재로드. 픽셀값을 읽기 위해서는 반드시 필요한 절차....
img.loadPixels();
for (int y = 0; y < height; y++ )
{
for (int x = 0; x < width; x++ )
{
int loc = x + y * width;
// The functions red(), green(), and blue() pull out the three color components from a pixel.
// 이미지 픽셀들의 위치 값을 저장하는 임시변수 loc 을 이용하여 플롯형 변수에 RGB 값 저장.
// img.pixels[픽셀위치] 구문을 사용하여 R, G, B 각각의 값을 구하는 방법은 다음과 같으므로 기억하자.
// red(), green(), blue() 안에 img.pixels[]가 들어간다는 건 pixels[]의 리턴값이 color 타입이라는 뜻이다!!
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
// Image Processing would go here.
// If we were to change the RGB values, we would do it here, before setting the pixel in the display window.
// Set the display pixel to the image pixel.
// 디스플레이 창에 픽셀값 정렬하는 부분.
pixels[loc] = color(r, g, b);
}
}
updatePixels(); // 왜 해줬을까..
}
이미지의 픽셀 컬러값을 하나하나 받아들여서 (일괄) 재배치하는 코드.
원 이미지의 크기(Pixel Dimension)와 상관 없이 200 바이 200 크기의 디스플레이 창에 차례로 늘어놓았다.
원 이미지
200 * 200 디스플레이 창
size(200, 200) 의 결과
포토샵을 이용하여 얻은 원 이미지의 Pixel Dimensions 정보 (580 * 386)
580 * 386 디스플레이 창
size(580, 386) 의 결과