void CriminisiInpainting::ComputeAllPriorities() { try { // Only compute priorities for pixels on the boundary itk::ImageRegionConstIterator<UnsignedCharScalarImageType> boundaryIterator(this->BoundaryImage, this->BoundaryImage->GetLargestPossibleRegion()); itk::ImageRegionIterator<FloatScalarImageType> priorityIterator(this->PriorityImage, this->PriorityImage->GetLargestPossibleRegion()); // Blank the priority image. this->PriorityImage->FillBuffer(0); // The main loop is over the boundary image. We only want to compute priorities at boundary pixels. unsigned int boundaryPixelCounter = 0; while(!boundaryIterator.IsAtEnd()) { if(boundaryIterator.Get() != 0) // Pixel is on the boundary { float priority = ComputePriority(boundaryIterator.GetIndex()); //DebugMessage<float>("Priority: ", priority); priorityIterator.Set(priority); boundaryPixelCounter++; } ++boundaryIterator; ++priorityIterator; } DebugMessage<unsigned int>("Number of boundary pixels: ", boundaryPixelCounter); } catch( itk::ExceptionObject & err ) { std::cerr << "ExceptionObject caught in ComputeAllPriorities!" << std::endl; std::cerr << err << std::endl; exit(-1); } }
CString DSRequest::dump() { CString outstr; switch(m_event) { case DSEMPTY: outstr="Idle. (Empty)"; break; case DSShutDownCommThread: outstr="ShutDownCommThread"; break; case DSSyncInitCommThread: outstr="DSSyncInitCommThread"; break; case DSTimerMsg: case DSWindowsMessage: outstr="Winmsg"; break; case RequestConnect: outstr="RequestConnect"; break; case RequestRemoveAll: outstr="RequestRemoveAll"; break; case RequestAddAttrib: outstr="RequestAddAttrib"; break; case RequestDisconnect: outstr="RequestDisconnect"; break; case RequestUploadChanges: outstr="RequestUploadChanges"; break; case RequestUpload: outstr="RequestUpload"; break; case RequestDownload: outstr="RequestDownload"; break; case RequestFindAttrib: outstr="RequestFindAttrib"; break; case RequestDeleteObject: outstr="RequestDeleteObject"; break; case RequestTestQueue: outstr="RequestTestQueue"; break; case RequestEnumerate: outstr="RequestEnumerate"; break; default: ASSERT(0); break; } outstr+=", Priority: "+str(ComputePriority())+", Entry #: "+str(m_lPriority); return outstr; }
void inpainting::UpdatePriority(int i, int j) { int x, y; for (y = MAX(j - myWinSize - 3, 0); y <= MIN(j + myWinSize + 3, m_height - 1); ++y) { for (x = MAX(i - myWinSize - 3, 0); x <= MIN(i + myWinSize + 3, m_width - 1); ++x) { if (m_mark[y * m_width + x] == BOUNDARY) { m_pri[y * m_width + x] = ComputePriority(x, y); } } } }
bool inpainting::Process(void) { char path[200]; char temp[30]; Convert2Gray(); DrawBoundary(); DrawSource(); memset(m_pri, 0, m_width*m_height*sizeof(double)); for(int j= m_top; j <= m_bottom; ++j) { for(int i = m_left; i <= m_right; ++i) { if(m_mark[j * m_width + i] == SOURCE) { number_to_fill_y[j] += 1; number_to_fill_x[i] += 1; if(number_to_fill_y[j]>max_width) { max_width=number_to_fill_y[j]; } if(number_to_fill_x[i]>max_height) { max_height=number_to_fill_x[i]; } } if(m_mark[j * m_width + i] == BOUNDARY) { m_pri[j * m_width + i] = ComputePriority(i,j); number_to_fill_y[j] += 1; number_to_fill_x[i] += 1; } } } int count=0; while(TargetExist()) { count++; double max_pri = 0; int pri_x,pri_y; for(int j= m_top; j <= m_bottom; ++j) { for(int i = m_left; i <= m_right; ++i) { if(m_mark[j * m_width + i] == BOUNDARY&&m_pri[j * m_width + i]>max_pri) { pri_x = i; pri_y = j; max_pri = m_pri[j * m_width + i]; } } } int patch_x, patch_y; PatchTexture(pri_x, pri_y, patch_x, patch_y); FillTarget(pri_x, pri_y, patch_x,patch_y, ComputeConfidence(pri_x,pri_y)); UpdateBoundary(pri_x, pri_y); UpdatePriority(pri_x, pri_y); } strcpy(path, save_path); strcat(path, ".bmp"); Image->Save(path); return true; }
inline BOOL DSRequest::operator<(DSRequest & right) { //Priority treatment of events. //We service all highest priority events first, then next lower priority, etc. //Within the same priority, we do first come, first serve. BYTE lpri=ComputePriority(); BYTE rpri=right.ComputePriority(); if(lpri==rpri) { //they're equal priority. Then use first come, first serve. return m_lPriority<right.m_lPriority; } else if(lpri>rpri) return FALSE; else //lpri<rpri return TRUE; }
std::string inpainting::Process(void) { char path[200]; char temp[30]; pix_to_inpaint = 0; pix_been_inpainted = 0; Convert2Gray(); DrawBoundary(); DrawSource(); memset(m_pri, 0, m_width*m_height*sizeof(double)); for (int j= m_top; j <= m_bottom; ++j) { for (int i = m_left; i <= m_right; ++i) { if (m_mark[j * m_width + i] == BOUNDARY) { m_pri[j * m_width + i] = ComputePriority(i, j); } } } int count = 0; count_pic =1; int temp_color = 0; int temp_color2 = 0; int *temp_colors = new int[LOOKUP]; int *temp_colors_2 = new int[LOOKUP]; int **most_similar_patch = new int*[LOOKUP]; for (int o = 0; o < LOOKUP; ++o) { most_similar_patch[o] = new int[2]; } int **most_similar_patch_2 = new int*[LOOKUP]; for (int o = 0; o < LOOKUP; ++o) { most_similar_patch_2[o] = new int[2]; } int start = clock(); int *colum_in_height = new int[m_height]; for (int i = 0; i < m_height; ++i) { colum_in_height[i] = 0; } int *colum_in_width = new int[m_width]; for (int i = 0; i < m_width; ++i) { colum_in_width[i] = 0; } double max_pri = 0; int pri_x, pri_y; int patch_x, patch_y; while (TargetExist()) { count++; count_pic++; max_pri = 0; for (int j= 0; j < m_height; ++j) { for (int i = 0; i < m_width; ++i) { colum_in_height[j]++; colum_in_width[i]++; if (m_mark[j * m_width + i] == BOUNDARY && m_pri[j * m_width + i] > max_pri) { pri_x = i; pri_y = j; max_pri = m_pri[j * m_width + i]; colum_in_height[j]--; colum_in_width[i]--; } if (m_mark[j * m_width + i] == TARGET) { colum_in_height[j]--; colum_in_width[i]--; } } } height_diff = m_bottom - m_top + 1; width_diff = m_right - m_left + 1; // 缩小搜索框 for (int i = m_top; i <= m_bottom; ++i) { if (colum_in_height[i] == width_diff) { m_top++; } else { break; } } for (int i = m_bottom-1; i >= m_top; --i) { if (colum_in_height[i] == width_diff) { m_bottom--; } else { break; } } for (int i = m_left; i <= m_right; ++i) { if (colum_in_width[i] == height_diff) { m_left++; } else { break; } } for (int i = m_right; i >= m_left; --i) { if (colum_in_width[i] == height_diff) { m_right--; } else { break; } } PatchTexture(pri_x, pri_y, patch_x, patch_y, most_similar_patch, most_similar_patch_2); FillTarget(pri_x, pri_y, patch_x, patch_y, ComputeConfidence(pri_x, pri_y)); UpdateBoundary(pri_x, pri_y); UpdatePriority(pri_x, pri_y); char str[10]; sprintf(str, "%d", count); strcpy(path, save_path); strcat(path, str); strcat(path, ".bmp"); // cout<<" path = "<<path<<endl; // Image -> save(path); // 下面的是为了画出最匹配的20个点的图片的中间步骤 /*temp_color = Image->pixel(pri_x,pri_y); temp_color2 = Image->pixel(patch_x,patch_y); for(int o=0;o<LOOKUP;++o) { temp_colors[o]=Image->pixel(most_similar_patch[o][0],most_similar_patch[o][1]); // temp_colors_2[o]=Image->pixel(most_similar_patch_2[o][0],most_similar_patch_2[o][1]); Image -> setPixel(most_similar_patch[o][0],most_similar_patch[o][1],MARK); // Image -> setPixel(most_similar_patch_2[o][0],most_similar_patch_2[o][1],MARK2); } Image -> setPixel(pri_x,pri_y,RED); Image -> setPixel(patch_x,patch_y,BLUE); //cout<<" patch_x = "<<patch_x<<endl; //cout<<" patch_y = "<<patch_y<<endl; Image -> save(path); for(int o=0;o<LOOKUP;++o) { Image -> setPixel(most_similar_patch[o][0],most_similar_patch[o][1],temp_colors[o]); // Image -> setPixel(most_similar_patch_2[o][0],most_similar_patch_2[o][1],temp_colors_2[o]); } Image -> setPixel(pri_x,pri_y,temp_color); Image -> setPixel(patch_x,patch_y,temp_color2);*/ } int end = clock(); strcpy(path, save_path); strcat(path, ".bmp"); // Image->Save(path); std::string res = path; return res; }